[PATCH v1 1/6] seq_buf: Mark binary printing functions with __printf() attribute

Andy Shevchenko posted 6 patches 9 months ago
There is a newer version of this series
[PATCH v1 1/6] seq_buf: Mark binary printing functions with __printf() attribute
Posted by Andy Shevchenko 9 months ago
Binary printing functions are using printf() type of format, and compiler
is not happy about them as is:

lib/seq_buf.c:162:17: error: function ‘seq_buf_bprintf’ 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/seq_buf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index fe41da005970..52791e070506 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -167,8 +167,8 @@ extern int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str,
 			    const void *buf, size_t len, bool ascii);
 
 #ifdef CONFIG_BINARY_PRINTF
-extern int
-seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
+__printf(2, 0)
+int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
 #endif
 
 void seq_buf_do_printk(struct seq_buf *s, const char *lvl);
-- 
2.47.2

Re: [PATCH v1 1/6] seq_buf: Mark binary printing functions with __printf() attribute
Posted by Steven Rostedt 8 months, 3 weeks ago
On Thu, 20 Mar 2025 20:04:22 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Binary printing functions are using printf() type of format, and compiler
> is not happy about them as is:
> 
> lib/seq_buf.c:162:17: error: function ‘seq_buf_bprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 
> Fix the compilation errors by adding __printf() attribute.
> 

Should also note the removal of "extern"

-- Steve

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/seq_buf.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
> index fe41da005970..52791e070506 100644
> --- a/include/linux/seq_buf.h
> +++ b/include/linux/seq_buf.h
> @@ -167,8 +167,8 @@ extern int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str,
>  			    const void *buf, size_t len, bool ascii);
>  
>  #ifdef CONFIG_BINARY_PRINTF
> -extern int
> -seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
> +__printf(2, 0)
> +int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
>  #endif
>  
>  void seq_buf_do_printk(struct seq_buf *s, const char *lvl);
Re: [PATCH v1 1/6] seq_buf: Mark binary printing functions with __printf() attribute
Posted by Andy Shevchenko 8 months, 3 weeks ago
On Mon, Mar 24, 2025 at 12:04:30PM -0400, Steven Rostedt wrote:
> On Thu, 20 Mar 2025 20:04:22 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Binary printing functions are using printf() type of format, and compiler
> > is not happy about them as is:
> > 
> > lib/seq_buf.c:162:17: error: function ‘seq_buf_bprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > 
> > Fix the compilation errors by adding __printf() attribute.
> > 
> 
> Should also note the removal of "extern"

Ah, just noticed that you are looking at v1, there is also v2 available:
20250321144822.324050-1-andriy.shevchenko@linux.intel.com

Thank you for the review, nevertheless!

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v1 1/6] seq_buf: Mark binary printing functions with __printf() attribute
Posted by Andy Shevchenko 8 months, 3 weeks ago
On Mon, Mar 24, 2025 at 6:03 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 20 Mar 2025 20:04:22 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > Binary printing functions are using printf() type of format, and compiler
> > is not happy about them as is:
> >
> > lib/seq_buf.c:162:17: error: function ‘seq_buf_bprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >
> > Fix the compilation errors by adding __printf() attribute.
>
> Should also note the removal of "extern"

If it is worth it, why not? The idea is to make it slightly more
consistent with code around (file seems to have both approaches).

-- 
With Best Regards,
Andy Shevchenko