* [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute
@ 2025-12-08 14:16 Andy Shevchenko
2025-12-16 9:35 ` Brendan Jackman
2026-02-04 15:59 ` Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-12-08 14:16 UTC (permalink / raw)
To: Peter Zijlstra, linux-kernel; +Cc: Andrew Morton, Andy Shevchenko
__warn_printf() is using printf() type of format, and compiler
is not happy about them as is:
lib/bug.c:187:25: error: function ‘__warn_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
187 | vprintk(fmt, *args);
| ^~~~~~~
Fix the compilation errors by adding __printf() attribute.
Fixes: 5c47b7f3d1a9 ("bug: Add BUG_FORMAT_ARGS infrastructure")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/bug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/bug.c b/lib/bug.c
index edd9041f89f3..d7db57280ab7 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -173,7 +173,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
return module_find_bug(bugaddr);
}
-static void __warn_printf(const char *fmt, struct pt_regs *regs)
+static __printf(1, 0) void __warn_printf(const char *fmt, struct pt_regs *regs)
{
if (!fmt)
return;
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute
2025-12-08 14:16 [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute Andy Shevchenko
@ 2025-12-16 9:35 ` Brendan Jackman
2026-02-04 15:59 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Brendan Jackman @ 2025-12-16 9:35 UTC (permalink / raw)
To: Andy Shevchenko, Peter Zijlstra, linux-kernel; +Cc: Andrew Morton
On Mon Dec 8, 2025 at 2:16 PM UTC, Andy Shevchenko wrote:
> __warn_printf() is using printf() type of format, and compiler
> is not happy about them as is:
>
> lib/bug.c:187:25: error: function ‘__warn_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 187 | vprintk(fmt, *args);
> | ^~~~~~~
>
> Fix the compilation errors by adding __printf() attribute.
>
> Fixes: 5c47b7f3d1a9 ("bug: Add BUG_FORMAT_ARGS infrastructure")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> lib/bug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/bug.c b/lib/bug.c
> index edd9041f89f3..d7db57280ab7 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -173,7 +173,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
> return module_find_bug(bugaddr);
> }
>
> -static void __warn_printf(const char *fmt, struct pt_regs *regs)
> +static __printf(1, 0) void __warn_printf(const char *fmt, struct pt_regs *regs)
> {
> if (!fmt)
> return;
In [0] I fixed this error by disabling the warning locally. My rationale
(which I didn't write in the patch, sorry) was that the pt_regs argument
doesn't correspond to any specifier in the format string so this was a
false positive.
However, I didn't realise you can specify 0 for the final arg - the GCC
docs[1] say:
> For functions where the arguments are not available to be checked
> (such as vprintf), specify the third parameter as zero. In this case
> the compiler only checks the format string for consistency.
So I think what what we get here is a check that the format string isn't
garbage, without any expectation that theres a %p or whatever for the
pt_regs.
Maybe it's worth noting this down in the commit message?
Other than that, thanks, this seems superior to my patch:
Reviewed-by: Brendan Jackman <jackmanb@google.com>
[0] https://lore.kernel.org/all/20251207-warn-printf-gcc-v1-1-b597d612b94b@google.com/
[1] https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Function-Attributes.html
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute
2025-12-08 14:16 [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute Andy Shevchenko
2025-12-16 9:35 ` Brendan Jackman
@ 2026-02-04 15:59 ` Andy Shevchenko
2026-02-04 16:20 ` Arnd Bergmann
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-04 15:59 UTC (permalink / raw)
To: Peter Zijlstra, linux-kernel; +Cc: Andrew Morton, Arnd Bergmann
+Cc: Arnd (just FYI)
On Mon, Dec 08, 2025 at 03:16:18PM +0100, Andy Shevchenko wrote:
> __warn_printf() is using printf() type of format, and compiler
> is not happy about them as is:
>
> lib/bug.c:187:25: error: function ‘__warn_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 187 | vprintk(fmt, *args);
> | ^~~~~~~
>
> Fix the compilation errors by adding __printf() attribute.
>
> Fixes: 5c47b7f3d1a9 ("bug: Add BUG_FORMAT_ARGS infrastructure")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> lib/bug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/bug.c b/lib/bug.c
> index edd9041f89f3..d7db57280ab7 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -173,7 +173,7 @@ struct bug_entry *find_bug(unsigned long bugaddr)
> return module_find_bug(bugaddr);
> }
>
> -static void __warn_printf(const char *fmt, struct pt_regs *regs)
> +static __printf(1, 0) void __warn_printf(const char *fmt, struct pt_regs *regs)
> {
> if (!fmt)
> return;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute
2026-02-04 15:59 ` Andy Shevchenko
@ 2026-02-04 16:20 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-02-04 16:20 UTC (permalink / raw)
To: Andy Shevchenko, Peter Zijlstra, linux-kernel
Cc: Andrew Morton, Brendan Jackman
On Wed, Feb 4, 2026, at 16:59, Andy Shevchenko wrote:
> +Cc: Arnd (just FYI)
>
> On Mon, Dec 08, 2025 at 03:16:18PM +0100, Andy Shevchenko wrote:
>> __warn_printf() is using printf() type of format, and compiler
>> is not happy about them as is:
>>
>> lib/bug.c:187:25: error: function ‘__warn_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>> 187 | vprintk(fmt, *args);
>> | ^~~~~~~
>>
>> Fix the compilation errors by adding __printf() attribute.
>>
>> Fixes: 5c47b7f3d1a9 ("bug: Add BUG_FORMAT_ARGS infrastructure")
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Yes, I think this is the correct fix. However, Brendan's patch is
now in the tip tree as d36067d6ea00 ("bug: Hush
suggest-attribute=format for __warn_printf()").
I hadn't seen your patch but did notice as well that the one
that was merged is not ideal. I decided against sending a fixup
because it looks harmless, but if you want to rebase your patch,
feel free to add
Acked-by: Arnd Bergmann <arnd@arndb.de>
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-04 16:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08 14:16 [PATCH v1 1/1] bug: Mark __warn_printf() with __printf() attribute Andy Shevchenko
2025-12-16 9:35 ` Brendan Jackman
2026-02-04 15:59 ` Andy Shevchenko
2026-02-04 16:20 ` Arnd Bergmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.