Skip to content

Commit b10545b

Browse files
committed
tracing/kprobes: Fix build error when find_module() is not available
The kernel test robot reported that the find_module() is not available if CONFIG_MODULES=n. Fix this error by hiding find_modules() in #ifdef CONFIG_MODULES with related rcu locks as try_module_get_by_name(). Link: https://lore.kernel.org/all/172056819167.201571.250053007194508038.stgit@devnote2/ Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 9d86160 commit b10545b

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,24 @@ static int validate_module_probe_symbol(const char *modname, const char *symbol)
794794
return 0;
795795
}
796796

797+
#ifdef CONFIG_MODULES
798+
/* Return NULL if the module is not loaded or under unloading. */
799+
static struct module *try_module_get_by_name(const char *name)
800+
{
801+
struct module *mod;
802+
803+
rcu_read_lock_sched();
804+
mod = find_module(name);
805+
if (mod && !try_module_get(mod))
806+
mod = NULL;
807+
rcu_read_unlock_sched();
808+
809+
return mod;
810+
}
811+
#else
812+
#define try_module_get_by_name(name) (NULL)
813+
#endif
814+
797815
static int validate_probe_symbol(char *symbol)
798816
{
799817
struct module *mod = NULL;
@@ -805,12 +823,7 @@ static int validate_probe_symbol(char *symbol)
805823
modname = symbol;
806824
symbol = p + 1;
807825
*p = '\0';
808-
/* Return 0 (defer) if the module does not exist yet. */
809-
rcu_read_lock_sched();
810-
mod = find_module(modname);
811-
if (mod && !try_module_get(mod))
812-
mod = NULL;
813-
rcu_read_unlock_sched();
826+
mod = try_module_get_by_name(modname);
814827
if (!mod)
815828
goto out;
816829
}

0 commit comments

Comments
 (0)