Skip to content

Commit 9d509a9

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 bb9de5c commit 9d509a9

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
@@ -432,6 +432,37 @@ int lookup_symbol_name(unsigned long addr, char *symname)
432432
return lookup_module_symbol_name(addr, symname);
433433
}
434434

435+
#ifdef CONFIG_STACKTRACE_BUILD_ID
436+
437+
static int append_buildid(char *buffer, const char *modname,
438+
const unsigned char *buildid)
439+
{
440+
if (!modname)
441+
return 0;
442+
443+
if (!buildid) {
444+
pr_warn_once("Undefined buildid for the module %s\n", modname);
445+
return 0;
446+
}
447+
448+
/* build ID should match length of sprintf */
449+
#ifdef CONFIG_MODULES
450+
static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
451+
#endif
452+
453+
return sprintf(buffer, " %20phN", buildid);
454+
}
455+
456+
#else /* CONFIG_STACKTRACE_BUILD_ID */
457+
458+
static int append_buildid(char *buffer, const char *modname,
459+
const unsigned char *buildid)
460+
{
461+
return 0;
462+
}
463+
464+
#endif /* CONFIG_STACKTRACE_BUILD_ID */
465+
435466
/* Look up a kernel symbol and return it in a text buffer. */
436467
static int __sprint_symbol(char *buffer, unsigned long address,
437468
int symbol_offset, int add_offset, int add_buildid)
@@ -454,15 +485,8 @@ static int __sprint_symbol(char *buffer, unsigned long address,
454485

455486
if (modname) {
456487
len += sprintf(buffer + len, " [%s", modname);
457-
#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
458-
if (add_buildid && buildid) {
459-
/* build ID should match length of sprintf */
460-
#if IS_ENABLED(CONFIG_MODULES)
461-
static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
462-
#endif
463-
len += sprintf(buffer + len, " %20phN", buildid);
464-
}
465-
#endif
488+
if (add_buildid)
489+
len += append_buildid(buffer + len, modname, buildid);
466490
len += sprintf(buffer + len, "]");
467491
}
468492

0 commit comments

Comments
 (0)