* [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl
@ 2022-06-12 17:44 Christophe Leroy
2022-06-12 17:44 ` [PATCH 2/2] module: Increase readability of module_kallsyms_lookup_name() Christophe Leroy
2022-06-12 19:35 ` [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Joe Perches
0 siblings, 2 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-06-12 17:44 UTC (permalink / raw)
To: Luis Chamberlain, linux-modules; +Cc: Christophe Leroy, linux-kernel
Checkpatch reports following errors:
ERROR: do not use assignment in if condition
+ if ((colon = strnchr(name, MODULE_NAME_LEN, ':')) != NULL) {
ERROR: do not use assignment in if condition
+ if ((mod = find_module_all(name, colon - name, false)) != NULL)
ERROR: do not use assignment in if condition
+ if ((ret = find_kallsyms_symbol_value(mod, name)) != 0)
ERROR: do not initialise globals to 0
+int modules_disabled = 0;
ERROR: do not use assignment in if condition
+ if (wait_event_interruptible_timeout(module_wq,
Fix them.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
kernel/module/kallsyms.c | 9 ++++++---
kernel/module/main.c | 6 +++---
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c
index 3e11523bc6f6..fe3636bde605 100644
--- a/kernel/module/kallsyms.c
+++ b/kernel/module/kallsyms.c
@@ -457,14 +457,17 @@ unsigned long module_kallsyms_lookup_name(const char *name)
/* Don't lock: we're in enough trouble already. */
preempt_disable();
- if ((colon = strnchr(name, MODULE_NAME_LEN, ':')) != NULL) {
- if ((mod = find_module_all(name, colon - name, false)) != NULL)
+ 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;
- if ((ret = find_kallsyms_symbol_value(mod, name)) != 0)
+ ret = find_kallsyms_symbol_value(mod, name);
+ if (ret)
break;
}
}
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 0548151dd933..36747941817f 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -119,7 +119,7 @@ static void mod_update_bounds(struct module *mod)
}
/* Block module loading/unloading? */
-int modules_disabled = 0;
+int modules_disabled;
core_param(nomodule, modules_disabled, bint, 0);
/* Waiting for a module to finish initializing? */
@@ -1111,9 +1111,9 @@ resolve_symbol_wait(struct module *mod,
const struct kernel_symbol *ksym;
char owner[MODULE_NAME_LEN];
+ ksym = resolve_symbol(mod, info, name, owner);
if (wait_event_interruptible_timeout(module_wq,
- !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
- || PTR_ERR(ksym) != -EBUSY,
+ !IS_ERR(ksym) || PTR_ERR(ksym) != -EBUSY,
30 * HZ) <= 0) {
pr_warn("%s: gave up waiting for init of module %s.\n",
mod->name, owner);
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] module: Increase readability of module_kallsyms_lookup_name()
2022-06-12 17:44 [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Christophe Leroy
@ 2022-06-12 17:44 ` Christophe Leroy
2022-06-12 19:35 ` [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Joe Perches
1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-06-12 17:44 UTC (permalink / raw)
To: Luis Chamberlain, linux-modules; +Cc: Christophe Leroy, linux-kernel
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(-)
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;
}
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl
2022-06-12 17:44 [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Christophe Leroy
2022-06-12 17:44 ` [PATCH 2/2] module: Increase readability of module_kallsyms_lookup_name() Christophe Leroy
@ 2022-06-12 19:35 ` Joe Perches
1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2022-06-12 19:35 UTC (permalink / raw)
To: Christophe Leroy, Luis Chamberlain, linux-modules; +Cc: linux-kernel
On Sun, 2022-06-12 at 19:44 +0200, Christophe Leroy wrote:
> Checkpatch reports following errors:
There are many conditions that checkpatch reports that do
not need fixing.
checkpatch is a mindless script. It's not always right.
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
[]
> diff --git a/kernel/module/main.c b/kernel/module/main.c
[]
> @@ -1111,9 +1111,9 @@ resolve_symbol_wait(struct module *mod,
> const struct kernel_symbol *ksym;
> char owner[MODULE_NAME_LEN];
>
> + ksym = resolve_symbol(mod, info, name, owner);
> if (wait_event_interruptible_timeout(module_wq,
Did you verify this change by looking at the code for
wait_event_interruptible_timeout?
> - !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
> - || PTR_ERR(ksym) != -EBUSY,
> + !IS_ERR(ksym) || PTR_ERR(ksym) != -EBUSY,
> 30 * HZ) <= 0) {
> pr_warn("%s: gave up waiting for init of module %s.\n",
> mod->name, owner);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-12 19:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 17:44 [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Christophe Leroy
2022-06-12 17:44 ` [PATCH 2/2] module: Increase readability of module_kallsyms_lookup_name() Christophe Leroy
2022-06-12 19:35 ` [PATCH 1/2] module: Fix ERRORs reported by checkpatch.pl Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).