linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] module: Fix "warning: variable 'exit' set but not used"
@ 2022-06-12 15:33 Christophe Leroy
  2022-07-01 21:45 ` Luis Chamberlain
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe Leroy @ 2022-06-12 15:33 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules
  Cc: Christophe Leroy, linux-kernel, kernel test robot

When CONFIG_MODULE_UNLOAD is not selected, 'exit' is
set but never used.

It is not possible to replace the #ifdef CONFIG_MODULE_UNLOAD by
IS_ENABLED(CONFIG_MODULE_UNLOAD) because mod->exit doesn't exist
when CONFIG_MODULE_UNLOAD is not selected.

And because of the rcu_read_lock_sched() section it is not easy
to regroup everything in a single #ifdef. Let's regroup partially
and add missing #ifdef to completely opt out the use of
'exit' when CONFIG_MODULE_UNLOAD is not selected.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 kernel/module/main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index fed58d30725d..0548151dd933 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2939,24 +2939,25 @@ static void cfi_init(struct module *mod)
 {
 #ifdef CONFIG_CFI_CLANG
 	initcall_t *init;
+#ifdef CONFIG_MODULE_UNLOAD
 	exitcall_t *exit;
+#endif
 
 	rcu_read_lock_sched();
 	mod->cfi_check = (cfi_check_fn)
 		find_kallsyms_symbol_value(mod, "__cfi_check");
 	init = (initcall_t *)
 		find_kallsyms_symbol_value(mod, "__cfi_jt_init_module");
-	exit = (exitcall_t *)
-		find_kallsyms_symbol_value(mod, "__cfi_jt_cleanup_module");
-	rcu_read_unlock_sched();
-
 	/* Fix init/exit functions to point to the CFI jump table */
 	if (init)
 		mod->init = *init;
 #ifdef CONFIG_MODULE_UNLOAD
+	exit = (exitcall_t *)
+		find_kallsyms_symbol_value(mod, "__cfi_jt_cleanup_module");
 	if (exit)
 		mod->exit = *exit;
 #endif
+	rcu_read_unlock_sched();
 
 	cfi_module_add(mod, mod_tree.addr_min);
 #endif
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] module: Fix "warning: variable 'exit' set but not used"
  2022-06-12 15:33 [PATCH] module: Fix "warning: variable 'exit' set but not used" Christophe Leroy
@ 2022-07-01 21:45 ` Luis Chamberlain
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Chamberlain @ 2022-07-01 21:45 UTC (permalink / raw)
  To: Christophe Leroy; +Cc: linux-modules, linux-kernel, kernel test robot

On Sun, Jun 12, 2022 at 05:33:20PM +0200, Christophe Leroy wrote:
> When CONFIG_MODULE_UNLOAD is not selected, 'exit' is
> set but never used.
> 
> It is not possible to replace the #ifdef CONFIG_MODULE_UNLOAD by
> IS_ENABLED(CONFIG_MODULE_UNLOAD) because mod->exit doesn't exist
> when CONFIG_MODULE_UNLOAD is not selected.
> 
> And because of the rcu_read_lock_sched() section it is not easy
> to regroup everything in a single #ifdef. Let's regroup partially
> and add missing #ifdef to completely opt out the use of
> 'exit' when CONFIG_MODULE_UNLOAD is not selected.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Queued up thanks!

  Luis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-01 21:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 15:33 [PATCH] module: Fix "warning: variable 'exit' set but not used" Christophe Leroy
2022-07-01 21:45 ` Luis Chamberlain

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).