Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

module: Fix "warning: variable 'exit' set but not used"

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>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Christophe Leroy and committed by
Luis Chamberlain
f963ef12 cfa94c53

+5 -4
+5 -4
kernel/module/main.c
··· 2939 2939 { 2940 2940 #ifdef CONFIG_CFI_CLANG 2941 2941 initcall_t *init; 2942 + #ifdef CONFIG_MODULE_UNLOAD 2942 2943 exitcall_t *exit; 2944 + #endif 2943 2945 2944 2946 rcu_read_lock_sched(); 2945 2947 mod->cfi_check = (cfi_check_fn) 2946 2948 find_kallsyms_symbol_value(mod, "__cfi_check"); 2947 2949 init = (initcall_t *) 2948 2950 find_kallsyms_symbol_value(mod, "__cfi_jt_init_module"); 2949 - exit = (exitcall_t *) 2950 - find_kallsyms_symbol_value(mod, "__cfi_jt_cleanup_module"); 2951 - rcu_read_unlock_sched(); 2952 - 2953 2951 /* Fix init/exit functions to point to the CFI jump table */ 2954 2952 if (init) 2955 2953 mod->init = *init; 2956 2954 #ifdef CONFIG_MODULE_UNLOAD 2955 + exit = (exitcall_t *) 2956 + find_kallsyms_symbol_value(mod, "__cfi_jt_cleanup_module"); 2957 2957 if (exit) 2958 2958 mod->exit = *exit; 2959 2959 #endif 2960 + rcu_read_unlock_sched(); 2960 2961 2961 2962 cfi_module_add(mod, mod_tree.addr_min); 2962 2963 #endif