diff mbox series

[v2,2/2] module: Increase readability of module_kallsyms_lookup_name()

Message ID 133321ea63ceb4cdd83346e068d1d16b676678f8.1655100096.git.christophe.leroy@csgroup.eu (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] module: Fix ERRORs reported by checkpatch.pl | expand

Commit Message

Christophe Leroy June 13, 2022, 6:02 a.m. UTC
module_kallsyms_lookup_name() has several exit conditions but
can't return immediately due to preempt_disable().

Refactor module_kallsyms_lookup_name() to allow returning from
anywhere, and reduce depth.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 kernel/module/kallsyms.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

Comments

Luis Chamberlain July 1, 2022, 10:07 p.m. UTC | #1
On Mon, Jun 13, 2022 at 08:02:02AM +0200, Christophe Leroy wrote:
> module_kallsyms_lookup_name() has several exit conditions but
> can't return immediately due to preempt_disable().
> 
> Refactor module_kallsyms_lookup_name() to allow returning from
> anywhere, and reduce depth.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Thanks for this cleanup, holy crap that was gross before, queued up!

  Luis
diff mbox series

Patch

diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c
index fe3636bde605..df0150c467d4 100644
--- a/kernel/module/kallsyms.c
+++ b/kernel/module/kallsyms.c
@@ -448,29 +448,39 @@  unsigned long find_kallsyms_symbol_value(struct module *mod, const char *name)
 	return 0;
 }
 
-/* Look for this name: can be of form module:name. */
-unsigned long module_kallsyms_lookup_name(const char *name)
+static unsigned long __module_kallsyms_lookup_name(const char *name)
 {
 	struct module *mod;
 	char *colon;
-	unsigned long ret = 0;
 
-	/* Don't lock: we're in enough trouble already. */
-	preempt_disable();
 	colon = strnchr(name, MODULE_NAME_LEN, ':');
 	if (colon) {
 		mod = find_module_all(name, colon - name, false);
 		if (mod)
-			ret = find_kallsyms_symbol_value(mod, colon + 1);
-	} else {
-		list_for_each_entry_rcu(mod, &modules, list) {
-			if (mod->state == MODULE_STATE_UNFORMED)
-				continue;
-			ret = find_kallsyms_symbol_value(mod, name);
-			if (ret)
-				break;
-		}
+			return find_kallsyms_symbol_value(mod, colon + 1);
+		return 0;
 	}
+
+	list_for_each_entry_rcu(mod, &modules, list) {
+		unsigned long ret;
+
+		if (mod->state == MODULE_STATE_UNFORMED)
+			continue;
+		ret = find_kallsyms_symbol_value(mod, name);
+		if (ret)
+			return ret;
+	}
+	return 0;
+}
+
+/* Look for this name: can be of form module:name. */
+unsigned long module_kallsyms_lookup_name(const char *name)
+{
+	unsigned long ret;
+
+	/* Don't lock: we're in enough trouble already. */
+	preempt_disable();
+	ret = __module_kallsyms_lookup_name(name);
 	preempt_enable();
 	return ret;
 }