linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	kernel test robot <lkp@intel.com>,
	Maninder Singh <maninder1.s@samsung.com>,
	kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
	Johannes Weiner <hannes@cmpxchg.org>,
	Vaneet Narang <v.narang@samsung.com>,
	Linux Memory Management List <linux-mm@kvack.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>
Subject: Re: [hnaz-mm:master 272/379] lib/vsprintf.c:991:13: warning: variable 'modbuildid' set but not used
Date: Wed, 2 Mar 2022 10:56:37 +0100	[thread overview]
Message-ID: <Yh8/Vbu05MEQylMx@alley> (raw)
In-Reply-To: <Yh5yhoW+y9qcn1RM@casper.infradead.org>

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);
  ^~~


From 66f6166e968d8c7e752260e7ee7e1c0414cd2cce Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.com>
Date: Wed, 2 Mar 2022 10:03:14 +0100
Subject: [PATCH] vsprintf: Fix warnings about missing gnu_printf attribute in vsprintf.o
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The following warning is produced by: make W=1 lib/vsprintf.o

lib/vsprintf.c:1770:1: error: multiple storage classes in declaration specifiers
 static char *va_format(char *buf, char *end, struct va_format *va_fmt,
 ^~~~~~
lib/vsprintf.c:1770:14: warning: no previous prototype for ‘va_format’ [-Wmissing-prototypes]
 static char *va_format(char *buf, char *end, struct va_format *va_fmt,
              ^~~~~~~~~

More similar warnings are printed after fixing the 1st one:

lib/vsprintf.c: In function ‘pointer’:
lib/vsprintf.c:2522:3: warning: function ‘pointer’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
   return va_format(buf, end, ptr, spec, fmt);
   ^~~~~~
lib/vsprintf.c: In function ‘vbin_printf’:
lib/vsprintf.c:3213:12: warning: function ‘vbin_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
            spec);
            ^~~~
lib/vsprintf.c: In function ‘bstr_printf’:
lib/vsprintf.c:3398:5: warning: function ‘bstr_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
     str = pointer(fmt, str, end, get_arg(void *), spec);
     ^~~

Add the proposed annotation.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 include/linux/string.h | 3 +++
 lib/vsprintf.c         | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index b6572aeca2f5..e37eaecb7906 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -196,8 +196,11 @@ 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
+__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);
+__printf(3, 4)
 int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
 #endif
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3b8129dd374c..981c71da5e3d 100644
--- 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)
 {
@@ -2498,6 +2499,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
  * @precision: precision of a number
  * @qualifier: qualifier of a number (long, size_t, ...)
  */
+__printf(1, 0)
 static noinline_for_stack
 int format_decode(const char *fmt, struct printf_spec *spec)
 {
-- 
2.26.2



  parent reply	other threads:[~2022-03-02  9:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 12:11 kernel test robot
2022-03-01 18:24 ` Andrew Morton
2022-03-01 19:22   ` Matthew Wilcox
2022-03-02  9:52     ` John Ogness
2022-03-02 11:52       ` Petr Mladek
2022-03-02  9:56     ` Petr Mladek [this message]
2022-03-02 12:07   ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yh8/Vbu05MEQylMx@alley \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=john.ogness@linutronix.de \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=maninder1.s@samsung.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=v.narang@samsung.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox