mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Jiayuan Chen <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Cc: daniel@iogearbox.net, linux-kernel@vger.kernel.org,
	ast@kernel.org, davem@davemloft.net, kuba@kernel.org,
	hawk@kernel.org, john.fastabend@gmail.com, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, mrpre@163.com,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: [PATCH bpf-next v1 1/2] bpftool: Add -Wformat-signedness flag to detect format errors
Date: Mon, 10 Mar 2025 15:49:05 +0000	[thread overview]
Message-ID: <654713e8-f4ce-4742-8165-f73838ea8d16@kernel.org> (raw)
In-Reply-To: <20250310142037.45932-2-jiayuan.chen@linux.dev>

2025-03-10 22:20 UTC+0800 ~ Jiayuan Chen <jiayuan.chen@linux.dev>
> This commit adds the -Wformat-signedness compiler flag to detect and
> prevent printf format errors, where signed or unsigned types are
> mismatched with format specifiers. This helps to catch potential issues at
> compile-time, ensuring that our code is more robust and reliable. With
> this flag, the compiler will now warn about incorrect format strings, such
> as using %d with unsigned types or %u with signed types.
> 
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>


Acked-by: Quentin Monnet <qmo@kernel.org>

Thanks for that. Have you looked into enabling the flag along with the
other EXTRA_WARNINGS in tools/scripts/Makefile.include? It would be
ideal to have it there, but I suppose it raises too many warnings across
tools/? (I didn't try myself.) No objection to taking it in bpftool only.


> ---
>  tools/bpf/bpftool/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index dd9f3ec84201..d9f3eb51a48f 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -71,7 +71,7 @@ prefix ?= /usr/local
>  bash_compdir ?= /usr/share/bash-completion/completions
>  
>  CFLAGS += -O2
> -CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
> +CFLAGS += -W -Wall -Wextra -Wformat-signedness -Wno-unused-parameter -Wno-missing-field-initializers


Nit: This line is becoming long enough that I'd consider moving each
flag to its own line, for better reading:

	CFLAGS += -W
	CFLAGS += -Wall
	CFLAGS += -Wextra
	CFLAGS += -Wformat-signedness
	...

>  CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))
>  CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
>  	-I$(or $(OUTPUT),.) \


  reply	other threads:[~2025-03-10 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10 14:20 [PATCH bpf-next v1 0/2] bpftool: Using the right format specifiers Jiayuan Chen
2025-03-10 14:20 ` [PATCH bpf-next v1 1/2] bpftool: Add -Wformat-signedness flag to detect format errors Jiayuan Chen
2025-03-10 15:49   ` Quentin Monnet [this message]
2025-03-11  2:41     ` Jiayuan Chen
2025-03-10 14:20 ` [PATCH bpf-next v1 2/2] bpftool: Using the right format specifiers Jiayuan Chen
2025-03-10 15:49   ` Quentin Monnet

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=654713e8-f4ce-4742-8165-f73838ea8d16@kernel.org \
    --to=qmo@kernel.org \
    --cc=acme@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mrpre@163.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®