Skip to content

Commit 0f6f49a

Browse files
committed
Fix caller information for warn_slowpath_null
Ian Campbell noticed that since "Eliminate thousands of warnings with gcc 3.2 build" (commit 57adc4d) all WARN_ON()'s currently appear to come from warn_slowpath_null(), eg: WARNING: at kernel/softirq.c:143 warn_slowpath_null+0x1c/0x20() because now that warn_slowpath_null() is in the call path, the __builtin_return_address(0) returns that, rather than the place that caused the warning. Fix this by splitting up the warn_slowpath_null/fmt cases differently, using a common helper function, and getting the return address in the right place. This also happens to avoid the unnecessary stack usage for the non-stdargs case, and just generally cleans things up. Make the function name printout use %pS while at it. Cc: Ian Campbell <ian.campbell@citrix.com> Cc: Jesper Nilsson <jesper.nilsson@axis.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Hugh Dickins <hugh@veritas.com> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b41a080 commit 0f6f49a

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

‎kernel/panic.c‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -340,39 +340,44 @@ void oops_exit(void)
340340
}
341341

342342
#ifdef WANT_WARN_ON_SLOWPATH
343-
void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
344-
{
343+
struct slowpath_args {
344+
const char *fmt;
345345
va_list args;
346-
char function[KSYM_SYMBOL_LEN];
347-
unsigned long caller = (unsigned long)__builtin_return_address(0);
348-
const char *board;
346+
};
349347

350-
sprint_symbol(function, caller);
348+
static void warn_slowpath_common(const char *file, int line, void *caller, struct slowpath_args *args)
349+
{
350+
const char *board;
351351

352352
printk(KERN_WARNING "------------[ cut here ]------------\n");
353-
printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file,
354-
line, function);
353+
printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
355354
board = dmi_get_system_info(DMI_PRODUCT_NAME);
356355
if (board)
357356
printk(KERN_WARNING "Hardware name: %s\n", board);
358357

359-
if (*fmt) {
360-
va_start(args, fmt);
361-
vprintk(fmt, args);
362-
va_end(args);
363-
}
358+
if (args)
359+
vprintk(args->fmt, args->args);
364360

365361
print_modules();
366362
dump_stack();
367363
print_oops_end_marker();
368364
add_taint(TAINT_WARN);
369365
}
366+
367+
void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
368+
{
369+
struct slowpath_args args;
370+
371+
args.fmt = fmt;
372+
va_start(args.args, fmt);
373+
warn_slowpath_common(file, line, __builtin_return_address(0), &args);
374+
va_end(args.args);
375+
}
370376
EXPORT_SYMBOL(warn_slowpath_fmt);
371377

372378
void warn_slowpath_null(const char *file, int line)
373379
{
374-
static const char *empty = "";
375-
warn_slowpath_fmt(file, line, empty);
380+
warn_slowpath_common(file, line, __builtin_return_address(0), NULL);
376381
}
377382
EXPORT_SYMBOL(warn_slowpath_null);
378383
#endif

0 commit comments

Comments
 (0)