* [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk()
@ 2026-02-03 16:45 Arnd Bergmann
2026-02-04 13:49 ` Andy Shevchenko
2026-02-04 21:48 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2026-02-03 16:45 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Anna Schumaker, Jeff Layton,
Chuck Lever, Simon Horman
Cc: Arnd Bergmann, Mathieu Desnoyers, Andrew Morton, Andy Shevchenko,
Yury Norov, Randy Dunlap, linux-kernel, linux-trace-kernel
From: Arnd Bergmann <arnd@arndb.de>
The sunrpc change to use trace_printk() for debugging caused
a new warning for every instance of dprintk() in some configurations,
when -Wformat-security is enabled:
fs/nfs/getroot.c: In function 'nfs_get_root':
fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
90 | nfs_errorf(fc, "NFS: Couldn't getattr on root");
I've been slowly chipping away at those warnings over time with the
intention of enabling them by default in the future. While I could not
figure out why this only happens for this one instance, I see that the
__trace_bprintk() function is always called with a local variable as
the format string, rather than a literal.
Move the __printf(2,3) annotation on this function from the declaration
to the caller. As this is can only be validated for literals, the
attribute on the declaration causes the warnings every time, but
removing it entirely introduces a new warning on the __ftrace_vbprintk()
definition.
The format strings still get checked because the underlying literal keeps
getting passed into __trace_printk() in the "else" branch, which is not
taken but still evaluated for compile-time warnings.
Fixes: ec7d8e68ef0e ("sunrpc: add a Kconfig option to redirect dfprintk() output to trace buffer")
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: included fix for regression reported by kernel test robot <lkp@intel.com>
---
include/linux/trace_printk.h | 1 -
kernel/trace/trace_printk.c | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/trace_printk.h b/include/linux/trace_printk.h
index bb5874097f24..2670ec7f4262 100644
--- a/include/linux/trace_printk.h
+++ b/include/linux/trace_printk.h
@@ -107,7 +107,6 @@ do { \
__trace_printk(_THIS_IP_, fmt, ##args); \
} while (0)
-extern __printf(2, 3)
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
extern __printf(2, 3)
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 29f6e95439b6..48c085fcae7a 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -197,6 +197,7 @@ struct notifier_block module_trace_bprintk_format_nb = {
.notifier_call = module_trace_bprintk_format_notify,
};
+__printf(2, 3)
int __trace_bprintk(unsigned long ip, const char *fmt, ...)
{
int ret;
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk()
2026-02-03 16:45 [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk() Arnd Bergmann
@ 2026-02-04 13:49 ` Andy Shevchenko
2026-02-04 21:48 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-02-04 13:49 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Steven Rostedt, Masami Hiramatsu, Anna Schumaker, Jeff Layton,
Chuck Lever, Simon Horman, Arnd Bergmann, Mathieu Desnoyers,
Andrew Morton, Yury Norov, Randy Dunlap, linux-kernel,
linux-trace-kernel
On Tue, Feb 03, 2026 at 05:45:29PM +0100, Arnd Bergmann wrote:
> The sunrpc change to use trace_printk() for debugging caused
> a new warning for every instance of dprintk() in some configurations,
> when -Wformat-security is enabled:
>
> fs/nfs/getroot.c: In function 'nfs_get_root':
> fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
> 90 | nfs_errorf(fc, "NFS: Couldn't getattr on root");
>
> I've been slowly chipping away at those warnings over time with the
> intention of enabling them by default in the future. While I could not
> figure out why this only happens for this one instance, I see that the
> __trace_bprintk() function is always called with a local variable as
> the format string, rather than a literal.
>
> Move the __printf(2,3) annotation on this function from the declaration
> to the caller. As this is can only be validated for literals, the
> attribute on the declaration causes the warnings every time, but
> removing it entirely introduces a new warning on the __ftrace_vbprintk()
> definition.
>
> The format strings still get checked because the underlying literal keeps
> getting passed into __trace_printk() in the "else" branch, which is not
> taken but still evaluated for compile-time warnings.
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk()
2026-02-03 16:45 [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk() Arnd Bergmann
2026-02-04 13:49 ` Andy Shevchenko
@ 2026-02-04 21:48 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2026-02-04 21:48 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Steven Rostedt, Masami Hiramatsu, Anna Schumaker, Jeff Layton,
Chuck Lever, Simon Horman, Arnd Bergmann, Mathieu Desnoyers,
Andrew Morton, Andy Shevchenko, Yury Norov, Randy Dunlap,
linux-kernel, linux-trace-kernel
On Tue, 3 Feb 2026 17:45:29 +0100
Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The sunrpc change to use trace_printk() for debugging caused
> a new warning for every instance of dprintk() in some configurations,
> when -Wformat-security is enabled:
>
> fs/nfs/getroot.c: In function 'nfs_get_root':
> fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
> 90 | nfs_errorf(fc, "NFS: Couldn't getattr on root");
>
> I've been slowly chipping away at those warnings over time with the
> intention of enabling them by default in the future. While I could not
> figure out why this only happens for this one instance, I see that the
> __trace_bprintk() function is always called with a local variable as
> the format string, rather than a literal.
>
> Move the __printf(2,3) annotation on this function from the declaration
> to the caller. As this is can only be validated for literals, the
^ definition ?
David
> attribute on the declaration causes the warnings every time, but
> removing it entirely introduces a new warning on the __ftrace_vbprintk()
> definition.
>
> The format strings still get checked because the underlying literal keeps
> getting passed into __trace_printk() in the "else" branch, which is not
> taken but still evaluated for compile-time warnings.
>
> Fixes: ec7d8e68ef0e ("sunrpc: add a Kconfig option to redirect dfprintk() output to trace buffer")
> Acked-by: Jeff Layton <jlayton@kernel.org>
> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: included fix for regression reported by kernel test robot <lkp@intel.com>
> ---
> include/linux/trace_printk.h | 1 -
> kernel/trace/trace_printk.c | 1 +
> 2 files changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/trace_printk.h b/include/linux/trace_printk.h
> index bb5874097f24..2670ec7f4262 100644
> --- a/include/linux/trace_printk.h
> +++ b/include/linux/trace_printk.h
> @@ -107,7 +107,6 @@ do { \
> __trace_printk(_THIS_IP_, fmt, ##args); \
> } while (0)
>
> -extern __printf(2, 3)
> int __trace_bprintk(unsigned long ip, const char *fmt, ...);
>
> extern __printf(2, 3)
> diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
> index 29f6e95439b6..48c085fcae7a 100644
> --- a/kernel/trace/trace_printk.c
> +++ b/kernel/trace/trace_printk.c
> @@ -197,6 +197,7 @@ struct notifier_block module_trace_bprintk_format_nb = {
> .notifier_call = module_trace_bprintk_format_notify,
> };
>
> +__printf(2, 3)
> int __trace_bprintk(unsigned long ip, const char *fmt, ...)
> {
> int ret;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-04 21:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 16:45 [PATCH] [v2] tracing: move __printf() attribute on __ftrace_vbprintk() Arnd Bergmann
2026-02-04 13:49 ` Andy Shevchenko
2026-02-04 21:48 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox