]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kallsyms: clean up modname and modbuildid initialization in kallsyms_lookup_buildid()
authorPetr Mladek <pmladek@suse.com>
Fri, 28 Nov 2025 13:59:15 +0000 (14:59 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:44:21 +0000 (19:44 -0800)
The @modname and @modbuildid optional return parameters are set only when
the symbol is in a module.

Always initialize them so that they do not need to be cleared when the
module is not in a module.  It simplifies the logic and makes the code
even slightly more safe.

Note that bpf_address_lookup() function will get updated in a separate
patch.

Link: https://lkml.kernel.org/r/20251128135920.217303-3-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Cc: Aaron Tomlin <atomlin@atomlin.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Daniel Gomez <da.gomez@samsung.com>
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: Petr Pavlu <petr.pavlu@suse.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/kallsyms.c

index 9559bf947c6b5074fdd4cefe9dfd0797532c92ca..66ad899124c51797d281eaf60469709aca8ba8fa 100644 (file)
@@ -362,6 +362,14 @@ static int kallsyms_lookup_buildid(unsigned long addr,
         * or empty string.
         */
        namebuf[0] = 0;
+       /*
+        * Initialize the module-related return values. They are not set
+        * when the symbol is in vmlinux or it is a bpf address.
+        */
+       if (modname)
+               *modname = NULL;
+       if (modbuildid)
+               *modbuildid = NULL;
 
        if (is_ksym_addr(addr)) {
                unsigned long pos;
@@ -370,10 +378,6 @@ static int kallsyms_lookup_buildid(unsigned long addr,
                /* Grab name */
                kallsyms_expand_symbol(get_symbol_offset(pos),
                                       namebuf, KSYM_NAME_LEN);
-               if (modname)
-                       *modname = NULL;
-               if (modbuildid)
-                       *modbuildid = NULL;
 
                return strlen(namebuf);
        }