]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
module: add helper function for reading module_buildid()
authorPetr Mladek <pmladek@suse.com>
Fri, 28 Nov 2025 13:59:16 +0000 (14:59 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:44:22 +0000 (19:44 -0800)
Add a helper function for reading the optional "build_id" member of struct
module.  It is going to be used also in ftrace_mod_address_lookup().

Use "#ifdef" instead of "#if IS_ENABLED()" to match the declaration of the
optional field in struct module.

Link: https://lkml.kernel.org/r/20251128135920.217303-4-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Cc: Aaron Tomlin <atomlin@atomlin.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Luis Chamberalin <mcgrof@kernel.org>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/module.h
kernel/module/kallsyms.c

index d80c3ea5747266bb2d30ad1c31c84019b795ab43..ac254525014cd6170d9881dbe91382792d2d7825 100644 (file)
@@ -748,6 +748,15 @@ static inline void __module_get(struct module *module)
        __mod ? __mod->name : "kernel";         \
 })
 
+static inline const unsigned char *module_buildid(struct module *mod)
+{
+#ifdef CONFIG_STACKTRACE_BUILD_ID
+       return mod->build_id;
+#else
+       return NULL;
+#endif
+}
+
 /* Dereference module function descriptor */
 void *dereference_module_function_descriptor(struct module *mod, void *ptr);
 
index 00a60796327c0611049acfeb33ed8d1308dca0ae..0fc11e45df9b912ae2d590c42eb5a166045f5522 100644 (file)
@@ -334,13 +334,8 @@ int module_address_lookup(unsigned long addr,
        if (mod) {
                if (modname)
                        *modname = mod->name;
-               if (modbuildid) {
-#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
-                       *modbuildid = mod->build_id;
-#else
-                       *modbuildid = NULL;
-#endif
-               }
+               if (modbuildid)
+                       *modbuildid = module_buildid(mod);
 
                sym = find_kallsyms_symbol(mod, addr, size, offset);