Skip to content

Commit e297e13

Browse files
pmladekKernel Patches Daemon
authored andcommitted
kallsyms: Cleanup code for appending the module buildid
Put the code for appending the optional "buildid" into a helper function, It makes __sprint_symbol() better readable. Also print a warning when the "modname" is set and the "buildid" isn't. It might catch a situation when some lookup function in kallsyms_lookup_buildid() does not handle the "buildid". Use pr_*_once() to avoid an infinite recursion when the function is called from printk(). The recursion is rather theoretical but better be on the safe side. Signed-off-by: Petr Mladek <[email protected]>
1 parent 39d2df3 commit e297e13

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

kernel/kallsyms.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,37 @@ int lookup_symbol_name(unsigned long addr, char *symname)
423423
return lookup_module_symbol_name(addr, symname);
424424
}
425425

426+
#ifdef CONFIG_STACKTRACE_BUILD_ID
427+
428+
static int append_buildid(char *buffer, const char *modname,
429+
const unsigned char *buildid)
430+
{
431+
if (!modname)
432+
return 0;
433+
434+
if (!buildid) {
435+
pr_warn_once("Undefined buildid for the module %s\n", modname);
436+
return 0;
437+
}
438+
439+
/* build ID should match length of sprintf */
440+
#ifdef CONFIG_MODULES
441+
static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
442+
#endif
443+
444+
return sprintf(buffer, " %20phN", buildid);
445+
}
446+
447+
#else /* CONFIG_STACKTRACE_BUILD_ID */
448+
449+
static int append_buildid(char *buffer, const char *modname,
450+
const unsigned char *buildid)
451+
{
452+
return 0;
453+
}
454+
455+
#endif /* CONFIG_STACKTRACE_BUILD_ID */
456+
426457
/* Look up a kernel symbol and return it in a text buffer. */
427458
static int __sprint_symbol(char *buffer, unsigned long address,
428459
int symbol_offset, int add_offset, int add_buildid)
@@ -445,15 +476,8 @@ static int __sprint_symbol(char *buffer, unsigned long address,
445476

446477
if (modname) {
447478
len += sprintf(buffer + len, " [%s", modname);
448-
#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
449-
if (add_buildid && buildid) {
450-
/* build ID should match length of sprintf */
451-
#if IS_ENABLED(CONFIG_MODULES)
452-
static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
453-
#endif
454-
len += sprintf(buffer + len, " %20phN", buildid);
455-
}
456-
#endif
479+
if (add_buildid)
480+
len += append_buildid(buffer + len, modname, buildid);
457481
len += sprintf(buffer + len, "]");
458482
}
459483

0 commit comments

Comments
 (0)