BPF List
 help / color / mirror / Atom feed
From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: "Quentin Monnet" <qmo@kernel.org>, 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: Tue, 11 Mar 2025 02:41:07 +0000	[thread overview]
Message-ID: <821170d2c5d570ca7961e7f91169110dcce5449c@linux.dev> (raw)
In-Reply-To: <654713e8-f4ce-4742-8165-f73838ea8d16@kernel.org>

March 10, 2025 at 23:49, "Quentin Monnet" <qmo@kernel.org> wrote:

> 
> 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.
> 

Thanks for reminding me of these.

I tried adding it to Makefile.include, and indeed there were a lot of warnings,
but this part is not part of bpftool. I'll take a look later and try to enable this
options to fix these warnings as well. For now, I'll only fix the warnings related
to bpftool and these changes can also be easily synced to the bpftool on github.

> > ---
> > 
> >  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
> 
>  ...
OK,I will do this.

  reply	other threads:[~2025-03-11  2:41 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
2025-03-11  2:41     ` Jiayuan Chen [this message]
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=821170d2c5d570ca7961e7f91169110dcce5449c@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --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=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=qmo@kernel.org \
    --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