panic: suppress gnu_printf warning
PATCH 1/1 panic: suppress gnu_printf warning
with GCC 13.2.1 and W=1, there's compiling warning like this:
kernel/panic.c: In function ‘__warn’:kernel/panic.c:676:17: warning: function ‘__warn’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
676 | vprintk(args->fmt, args->args);
| ^~~~~~~The normal __printf(x,y) adding can't fix it. So add workaround which disables -Wsuggest-attribute=format to mute it.
--- kernel/panic.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/panic.c +5 -0
@@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,pr_warn ("WARNING: CPU: %d PID: %d at %pS\n" ,raw_smp_processor_id (), current->pid, caller); +#pragma GCC diagnostic push +#ifndef __clang__ +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif if (args)vprintk (args->fmt, args->args); +#pragma GCC diagnostic popprint_modules ();
Signature · 1 line
2.41.0
Quoted 17 lines · On Sun, 7 Jan 2024 17:16:41 +0800 Baoquan He <[email protected]> wrote:
with GCC 13.2.1 and W=1, there's compiling warning like this:
kernel/panic.c: In function ‘__warn’:kernel/panic.c:676:17: warning: function ‘__warn’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]676 | vprintk(args->fmt, args->args); | ^~~~~~~The normal
__printf(x,y)adding can't fix it. So add workaround which disables -Wsuggest-attribute=format to mute it....
kernel/panic.c +0
-0@@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,pr_warn ("WARNING: CPU: %d PID: %d at %pS\n" ,raw_smp_processor_id (), current->pid, caller);
kernel/panic.c void __warn(const char *file, int line, void *caller, unsigned taint, · line 677
Quoted 10 lines
kernel/panic.c +5
-0+#pragma GCC diagnostic push +#ifndef __clang__ +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif if (args)vprintk (args->fmt, args->args); +#pragma GCC diagnostic popprint_modules ();
__warn() clearly isn't such a candidate. I'm suspecting that gcc's implementation of this warning is pretty crude. Is it a new thing in gcc-13.2?
A bit of context for [email protected]:
struct warn_args {
const char *fmt;
va_list args;
};...
void __warn(const char *file, int line, void *caller, unsigned taint,
struct pt_regs *regs, struct warn_args *args)
{
disable_trace_on_warning();
if (file)
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
raw_smp_processor_id(), current->pid, file, line,
caller);
else
pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
raw_smp_processor_id(), current->pid, caller);
if (args)
vprintk(args->fmt, args->args);
print_modules();
if (regs)
show_regs(regs);
check_panic_on_warn("kernel");
if (!regs)
dump_stack();
print_irqtrace_events(current);
print_oops_end_marker();
trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller);
/* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK);
}Quoted 28 lines · Andrew Morton
Quoted 26 lines · On Sun, 7 Jan 2024 17:16:41 +0800 Baoquan He <[email protected]> wrote:
with GCC 13.2.1 and W=1, there's compiling warning like this:
kernel/panic.c: In function ‘__warn’:kernel/panic.c:676:17: warning: function ‘__warn’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]676 | vprintk(args->fmt, args->args); | ^~~~~~~The normal
__printf(x,y)adding can't fix it. So add workaround which disables -Wsuggest-attribute=format to mute it....
kernel/panic.c +5
-0@@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,pr_warn ("WARNING: CPU: %d PID: %d at %pS\n" ,raw_smp_processor_id (), current->pid, caller); +#pragma GCC diagnostic push +#ifndef __clang__ +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif if (args)vprintk (args->fmt, args->args); +#pragma GCC diagnostic pop
Quoted 5 lines
kernel/panic.c void __warn(const char *file, int line, void *caller, unsigned taint, · line 677
Quoted 1 line
kernel/panic.c +0
-0print_modules ();
__warn()clearly isn't such a candidate. I'm suspecting that gcc's implementation of this warning is pretty crude. Is it a new thing in gcc-13.2?
Yeah, this isn't like other warnings in kernel. The compiler seems too smart by look into the parameter 'args' of 'struct warn_args*'.
Quoted 45 lines
A bit of context for [email protected]:
struct warn_args { const char *fmt; va_list args; };...
void __warn(const char *file, int line, void *caller, unsigned taint,
structpt_regs*regs, structwarn_args*args){ disable_trace_on_warning(); if (file) pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n", raw_smp_processor_id(), current->pid, file, line, caller); else pr_warn("WARNING: CPU: %d PID: %d at %pS\n", raw_smp_processor_id(), current->pid, caller); if (args) vprintk(args->fmt, args->args); print_modules(); if (regs) show_regs(regs); check_panic_on_warn("kernel"); if (!regs) dump_stack(); print_irqtrace_events(current); print_oops_end_marker(); trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller); /* Just a warning, don't kill lockdep. */ add_taint(taint, LOCKDEP_STILL_OK); }