diff mbox series

[v2,4/6] vsnprintf: Mark binary printing functions with __printf() attribute

Message ID 20250321144822.324050-5-andriy.shevchenko@linux.intel.com (mailing list archive)
State New
Headers show
Series vsprintf: Add __printf attribute to where it's required | expand

Commit Message

Andy Shevchenko March 21, 2025, 2:40 p.m. UTC
Binary printf() functions are using printf() type of format, and compiler
is not happy about them as is:

lib/vsprintf.c:3130:47: error: function ‘vbin_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
lib/vsprintf.c:3298:33: error: function ‘bstr_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

Fix the compilation errors by adding __printf() attribute.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/string.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Steven Rostedt March 24, 2025, 7:20 p.m. UTC | #1
On Fri, 21 Mar 2025 16:40:50 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Binary printf() functions are using printf() type of format, and compiler
> is not happy about them as is:
> 
> lib/vsprintf.c:3130:47: error: function ‘vbin_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> lib/vsprintf.c:3298:33: error: function ‘bstr_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

BTW, I find it disturbing that the compiler is set to "error" on a warning
that "might be a candidate". What happens if it is not? We have to play
games to quiet it.

Adding __printf() attributes to stubs seems to be a case of the compiler
causing more problems than its worth :-/

I honestly hate this error on warning because it causes real pain when
debugging. There's a lot of times I don't know if the value is long or long
long, and when I get it wrong, my printk() causes the build to fail. It's
especially annoying when both long and long long are the same size!

Fixing theses stupid errors takes a non trivial amount of time away from
actual debugging.

-- Steve


> 
> Fix the compilation errors by adding __printf() attribute.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Andy Shevchenko March 24, 2025, 7:32 p.m. UTC | #2
On Mon, Mar 24, 2025 at 03:20:12PM -0400, Steven Rostedt wrote:
> On Fri, 21 Mar 2025 16:40:50 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Binary printf() functions are using printf() type of format, and compiler
> > is not happy about them as is:
> > 
> > lib/vsprintf.c:3130:47: error: function ‘vbin_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > lib/vsprintf.c:3298:33: error: function ‘bstr_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 
> BTW, I find it disturbing that the compiler is set to "error" on a warning
> that "might be a candidate". What happens if it is not? We have to play
> games to quiet it.
> 
> Adding __printf() attributes to stubs seems to be a case of the compiler
> causing more problems than its worth :-/
> 
> I honestly hate this error on warning because it causes real pain when
> debugging. 

Tell it to Linus :-) since it was him who enabled that default. And since it's
there and defconfigs are also part of the kernel I can't easy remove that, and
TBH I even won't dare doing that.

> There's a lot of times I don't know if the value is long or long
> long, and when I get it wrong, my printk() causes the build to fail. It's
> especially annoying when both long and long long are the same size!
> 
> Fixing theses stupid errors takes a non trivial amount of time away from
> actual debugging.

You (actually me) fix them once, currently CI's typically run with W=1, but
with WERROR=n. Which means that the new code that is not fixed a priori, will
induce the CI red report.

> > Fix the compilation errors by adding __printf() attribute.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
diff mbox series

Patch

diff --git a/include/linux/string.h b/include/linux/string.h
index f8e21e80942f..f15696e8e4d4 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -336,8 +336,8 @@  int __sysfs_match_string(const char * const *array, size_t n, const char *s);
 #define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
 
 #ifdef CONFIG_BINARY_PRINTF
-int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
-int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
+__printf(3, 0) int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
+__printf(3, 0) int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
 #endif
 
 extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,