Skip to content

Commit

Permalink
tracing/kprobes: Fix build error when find_module() is not available
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/2086138

commit b10545b upstream.

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]>
Cc: Thorsten Leemhuis <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Koichiro Den <[email protected]>
Signed-off-by: Roxana Nicolescu <[email protected]>
  • Loading branch information
mhiramat authored and mehmetb0 committed Nov 9, 2024
1 parent 0b3c94b commit 75e9baf
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions kernel/trace/trace_kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,24 @@ static int validate_module_probe_symbol(const char *modname, const char *symbol)
return 0;
}

#ifdef CONFIG_MODULES
/* Return NULL if the module is not loaded or under unloading. */
static struct module *try_module_get_by_name(const char *name)
{
struct module *mod;

rcu_read_lock_sched();
mod = find_module(name);
if (mod && !try_module_get(mod))
mod = NULL;
rcu_read_unlock_sched();

return mod;
}
#else
#define try_module_get_by_name(name) (NULL)
#endif

static int validate_probe_symbol(char *symbol)
{
struct module *mod = NULL;
Expand All @@ -787,12 +805,7 @@ static int validate_probe_symbol(char *symbol)
modname = symbol;
symbol = p + 1;
*p = '\0';
/* Return 0 (defer) if the module does not exist yet. */
rcu_read_lock_sched();
mod = find_module(modname);
if (mod && !try_module_get(mod))
mod = NULL;
rcu_read_unlock_sched();
mod = try_module_get_by_name(modname);
if (!mod)
goto out;
}
Expand Down

0 comments on commit 75e9baf

Please sign in to comment.