From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0477CC433F5 for ; Wed, 2 Mar 2022 09:56:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 928A58D0002; Wed, 2 Mar 2022 04:56:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D8BF8D0001; Wed, 2 Mar 2022 04:56:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EF028D0002; Wed, 2 Mar 2022 04:56:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 6E7B78D0001 for ; Wed, 2 Mar 2022 04:56:40 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 12B7188C6 for ; Wed, 2 Mar 2022 09:56:40 +0000 (UTC) X-FDA: 79198991760.16.3CE892D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf17.hostedemail.com (Postfix) with ESMTP id 88CB84000A for ; Wed, 2 Mar 2022 09:56:39 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 50A2B21121; Wed, 2 Mar 2022 09:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1646214998; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AsBBJp+vpeojcN6nK12nMkVYJtAIRctCNR7mUwGffGU=; b=jn8kfNZOwRxK667m3IpT1XdbOyixz/CozEsfm9DoPCJq/hAfv3kLcquT/0UJkIQKSH6dBq ZcQ3ia5vZQF7D7mbJxtKE6xvLjySKiQJ/6QSkq/iMmA4oA7YU1+6NJBlI5XHPcHs/EN5E5 3hEqfJ//XJinHfWS3qHN2s0oncTJTV0= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 93EA8A3B93; Wed, 2 Mar 2022 09:56:37 +0000 (UTC) Date: Wed, 2 Mar 2022 10:56:37 +0100 From: Petr Mladek To: Matthew Wilcox Cc: Andrew Morton , kernel test robot , Maninder Singh , kbuild-all@lists.01.org, linux-kernel@vger.kernel.org, Johannes Weiner , Vaneet Narang , Linux Memory Management List , Sergey Senozhatsky , Steven Rostedt , John Ogness Subject: Re: [hnaz-mm:master 272/379] lib/vsprintf.c:991:13: warning: variable 'modbuildid' set but not used Message-ID: References: <202203012040.uFWGm3My-lkp@intel.com> <20220301102448.ff9bf910213d705842a2dd45@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 88CB84000A X-Stat-Signature: afaxht18egigt7tas356q5k5y7gb7zfi Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=jn8kfNZO; spf=pass (imf17.hostedemail.com: domain of pmladek@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=pmladek@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspam-User: X-HE-Tag: 1646214999-622866 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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=3Dformat= ] > > > 1759 | buf +=3D vsnprintf(buf, end > buf ? end - buf : = 0, va_fmt->fmt, va); > > > | ^~~ > >=20 > > I wonder what this means. >=20 > It means the compiler thinks we might want to add: >=20 > __attribute__((format(gnu_printf, x, y))) to the function declaration s= o it > can type-check the arguments. >=20 > '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: >=20 > extern int > my_printf (void *my_object, const char *my_format, ...) > __attribute__ ((format (printf, 2, 3))); >=20 > causes the compiler to check the arguments in calls to 'my_printf' > for consistency with the 'printf' style format string argument > 'my_format'. >=20 >=20 > 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; } =20 +__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 =E2=80=98____bpf_trace_printk=E2=80= =99: kernel/trace/bpf_trace.c:383:2: warning: function =E2=80=98____bpf_trace_= printk=E2=80=99 might be a candidate for =E2=80=98gnu_printf=E2=80=99 for= mat attribute [-Wsuggest-attribute=3Dformat] ret =3D bstr_printf(buf, sizeof(buf), fmt, bin_args); ^~~ kernel/trace/bpf_trace.c: In function =E2=80=98____bpf_trace_vprintk=E2=80= =99: kernel/trace/bpf_trace.c:439:2: warning: function =E2=80=98____bpf_trace_= vprintk=E2=80=99 might be a candidate for =E2=80=98gnu_printf=E2=80=99 fo= rmat attribute [-Wsuggest-attribute=3Dformat] ret =3D bstr_printf(buf, sizeof(buf), fmt, bin_args); ^~~ >From 66f6166e968d8c7e752260e7ee7e1c0414cd2cce Mon Sep 17 00:00:00 2001 From: Petr Mladek Date: Wed, 2 Mar 2022 10:03:14 +0100 Subject: [PATCH] vsprintf: Fix warnings about missing gnu_printf attribut= e in vsprintf.o MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit The following warning is produced by: make W=3D1 lib/vsprintf.o lib/vsprintf.c:1770:1: error: multiple storage classes in declaration spe= cifiers static char *va_format(char *buf, char *end, struct va_format *va_fmt, ^~~~~~ lib/vsprintf.c:1770:14: warning: no previous prototype for =E2=80=98va_fo= rmat=E2=80=99 [-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 =E2=80=98pointer=E2=80=99: lib/vsprintf.c:2522:3: warning: function =E2=80=98pointer=E2=80=99 might = be a candidate for =E2=80=98gnu_printf=E2=80=99 format attribute [-Wsugge= st-attribute=3Dformat] return va_format(buf, end, ptr, spec, fmt); ^~~~~~ lib/vsprintf.c: In function =E2=80=98vbin_printf=E2=80=99: lib/vsprintf.c:3213:12: warning: function =E2=80=98vbin_printf=E2=80=99 m= ight be a candidate for =E2=80=98gnu_printf=E2=80=99 format attribute [-W= suggest-attribute=3Dformat] spec); ^~~~ lib/vsprintf.c: In function =E2=80=98bstr_printf=E2=80=99: lib/vsprintf.c:3398:5: warning: function =E2=80=98bstr_printf=E2=80=99 mi= ght be a candidate for =E2=80=98gnu_printf=E2=80=99 format attribute [-Ws= uggest-attribute=3Dformat] str =3D pointer(fmt, str, end, get_arg(void *), spec); ^~~ Add the proposed annotation. Signed-off-by: Petr Mladek --- 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) =20 #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 =20 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; } =20 +__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) { --=20 2.26.2