Re: [hnaz-mm:master 272/379] lib/vsprintf.c:991:13: warning: variable 'modbuildid' set but not used

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue 2022-03-01 19:22:46, Matthew Wilcox wrote:
> On Tue, Mar 01, 2022 at 10:24:48AM -0800, Andrew Morton wrote:
> > >    lib/vsprintf.c: In function 'va_format':
> > >    lib/vsprintf.c:1759:9: warning: function 'va_format' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
> > >     1759 |         buf += vsnprintf(buf, end > buf ? end - buf : 0, va_fmt->fmt, va);
> > >          |         ^~~
> > 
> > I wonder what this means.
> 
> It means the compiler thinks we might want to add:
> 
> __attribute__((format(gnu_printf, x, y))) to the function declaration so it
> can type-check the arguments.
> 
> 'format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
>      The 'format' attribute specifies that a function takes 'printf',
>      'scanf', 'strftime' or 'strfmon' style arguments that should be
>      type-checked against a format string.  For example, the
>      declaration:
> 
>           extern int
>           my_printf (void *my_object, const char *my_format, ...)
>                 __attribute__ ((format (printf, 2, 3)));
> 
>      causes the compiler to check the arguments in calls to 'my_printf'
>      for consistency with the 'printf' style format string argument
>      'my_format'.
> 
> 
> I haven't looked into this at all and have no idea if we should.

There is the macro __printf(x, y). This particular warning can be
fixed by:

--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1672,6 +1672,7 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 	return buf;
 }
 
+__printf(5, 0)
 static char *va_format(char *buf, char *end, struct va_format *va_fmt,
 		       struct printf_spec spec, const char *fmt)
 {


But it seems to be can of worms. I get more warnings after fixing this
one. The following patch calmed down the warnings in vsprintf.o. But
it triggered another warning elsewhere, for example:

kernel/trace/bpf_trace.c: In function ‘____bpf_trace_printk’:
kernel/trace/bpf_trace.c:383:2: warning: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
  ret = bstr_printf(buf, sizeof(buf), fmt, bin_args);
  ^~~
kernel/trace/bpf_trace.c: In function ‘____bpf_trace_vprintk’:
kernel/trace/bpf_trace.c:439:2: warning: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
  ret = bstr_printf(buf, sizeof(buf), fmt, bin_args);
  ^~~



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux