public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] [v2] bug: avoid format attribute warning for clang as well
@ 2026-03-23 20:55 Arnd Bergmann
  2026-03-24 10:37 ` Brendan Jackman
  2026-03-24 11:25 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2026-03-23 20:55 UTC (permalink / raw)
  To: Andrew Morton, Nathan Chancellor, Brendan Jackman, Ingo Molnar,
	Peter Zijlstra (Intel)
  Cc: Arnd Bergmann, Andy Shevchenko, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

Like gcc, clang-22 now also warns about a function that it
incorrectly identifies as a printf-style format:

lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
  179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
      | __attribute__((format(printf, 1, 0)))
  180 | {
  181 |         if (!fmt)
  182 |                 return;
  183 |
  184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
  185 |         if (regs) {
  186 |                 struct arch_va_list _args;
  187 |                 va_list *args = __warn_args(&_args, regs);
  188 |
  189 |                 if (args) {
  190 |                         vprintk(fmt, *args);
      |                                           ^

Revert the change that added a gcc-specific workaround, and instead add
the generic annotation that avoid the warning.

Fixes: d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Brendan Jackman <jackmanb@google.com>
Link: https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Replace my earlier patch with Andy's solution
---
 lib/bug.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/lib/bug.c b/lib/bug.c
index bbc301097749..224f4cfa4aa3 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -173,10 +173,8 @@ struct bug_entry *find_bug(unsigned long bugaddr)
 	return module_find_bug(bugaddr);
 }
 
-__diag_push();
-__diag_ignore(GCC, all, "-Wsuggest-attribute=format",
-	      "Not a valid __printf() conversion candidate.");
-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;
@@ -195,7 +193,6 @@ static void __warn_printf(const char *fmt, struct pt_regs *regs)
 
 	printk("%s", fmt);
 }
-__diag_pop();
 
 static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long bugaddr, struct pt_regs *regs)
 {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v2] bug: avoid format attribute warning for clang as well
  2026-03-23 20:55 [PATCH] [v2] bug: avoid format attribute warning for clang as well Arnd Bergmann
@ 2026-03-24 10:37 ` Brendan Jackman
  2026-03-24 11:25 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Brendan Jackman @ 2026-03-24 10:37 UTC (permalink / raw)
  To: Arnd Bergmann, Andrew Morton, Nathan Chancellor, Brendan Jackman,
	Ingo Molnar, Peter Zijlstra (Intel)
  Cc: Arnd Bergmann, Andy Shevchenko, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-kernel, llvm

On Mon Mar 23, 2026 at 8:55 PM UTC, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Like gcc, clang-22 now also warns about a function that it
> incorrectly identifies as a printf-style format:
>
> lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
>   179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
>       | __attribute__((format(printf, 1, 0)))
>   180 | {
>   181 |         if (!fmt)
>   182 |                 return;
>   183 |
>   184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
>   185 |         if (regs) {
>   186 |                 struct arch_va_list _args;
>   187 |                 va_list *args = __warn_args(&_args, regs);
>   188 |
>   189 |                 if (args) {
>   190 |                         vprintk(fmt, *args);
>       |                                           ^
>
> Revert the change that added a gcc-specific workaround, and instead add
> the generic annotation that avoid the warning.
>
> Fixes: d36067d6ea00 ("bug: Hush suggest-attribute=format for __warn_printf()")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Suggested-by: Brendan Jackman <jackmanb@google.com>
> Link: https://lore.kernel.org/all/20251208141618.2805983-1-andriy.shevchenko@linux.intel.com/T/#u
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thank you,

Reviewed-by: Brendan Jackman <jackmanb@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v2] bug: avoid format attribute warning for clang as well
  2026-03-23 20:55 [PATCH] [v2] bug: avoid format attribute warning for clang as well Arnd Bergmann
  2026-03-24 10:37 ` Brendan Jackman
@ 2026-03-24 11:25 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-03-24 11:25 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andrew Morton, Nathan Chancellor, Brendan Jackman, Ingo Molnar,
	Peter Zijlstra (Intel), Arnd Bergmann, Nick Desaulniers,
	Bill Wendling, Justin Stitt, linux-kernel, llvm

On Mon, Mar 23, 2026 at 09:55:16PM +0100, Arnd Bergmann wrote:

> Like gcc, clang-22 now also warns about a function that it
> incorrectly identifies as a printf-style format:
> 
> lib/bug.c:190:22: error: diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of '__warn_printf' [-Werror,-Wmissing-format-attribute]
>   179 | static void __warn_printf(const char *fmt, struct pt_regs *regs)
>       | __attribute__((format(printf, 1, 0)))
>   180 | {
>   181 |         if (!fmt)
>   182 |                 return;
>   183 |
>   184 | #ifdef HAVE_ARCH_BUG_FORMAT_ARGS
>   185 |         if (regs) {
>   186 |                 struct arch_va_list _args;
>   187 |                 va_list *args = __warn_args(&_args, regs);
>   188 |
>   189 |                 if (args) {
>   190 |                         vprintk(fmt, *args);
>       |                                           ^
> 
> Revert the change that added a gcc-specific workaround, and instead add
> the generic annotation that avoid the warning.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-24 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 20:55 [PATCH] [v2] bug: avoid format attribute warning for clang as well Arnd Bergmann
2026-03-24 10:37 ` Brendan Jackman
2026-03-24 11:25 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox