summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>2024-07-10 08:36:31 +0900
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-09-18 19:25:17 +0200
commitad78bcd111e31d495a6b40022969284cdee25d05 (patch)
tree5e46b5f23bd746667ecdbda06946a4ec75c97019 /kernel
parentabc8feacacf8fae10eecf6fea7865e8c1fee419c (diff)
downloadlinux-stable-ad78bcd111e31d495a6b40022969284cdee25d05.tar.gz
linux-stable-ad78bcd111e31d495a6b40022969284cdee25d05.tar.bz2
linux-stable-ad78bcd111e31d495a6b40022969284cdee25d05.zip
tracing/kprobes: Fix build error when find_module() is not available
commit b10545b6b86b7a0b3e26b4c2a5c99b72d49bc4de 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 <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202407070744.RcLkn8sq-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202407070917.VVUCBlaS-lkp@intel.com/ Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Thorsten Leemhuis <regressions@leemhuis.info> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/trace_kprobe.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 0d88922f8763..4481f8913dcc 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -794,6 +794,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;
@@ -805,12 +823,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;
}