]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tracing/kprobes: Fix build error when find_module() is not available
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Tue, 9 Jul 2024 23:36:31 +0000 (08:36 +0900)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 10 Jul 2024 00:47:00 +0000 (09:47 +0900)
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>
kernel/trace/trace_kprobe.c

index 4cee3442bcced3ddb4867c0593af440b9db4f945..61a6da808203e07328b9ec6e3d03fd1f286ae34a 100644 (file)
@@ -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;
        }