BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: liujing <liujing@cmss.chinamobile.com>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/bpf: bpftool:Fix the wrong format specifier
Date: Thu, 28 Nov 2024 09:58:52 +0000	[thread overview]
Message-ID: <0370e35c-a06b-40dd-90b4-50cc30db224c@kernel.org> (raw)
In-Reply-To: <20241128025551.2868-1-liujing@cmss.chinamobile.com>

Please drop the "tools/bpf: " part of the prefix in your patch title,
it's enough to keep "bpftool: ".


2024-11-28 10:55 UTC+0800 ~ liujing <liujing@cmss.chinamobile.com>
> The output format of unsigned int should be %u, and the output
> format of int should be %d, so fix it.
> 
> Signed-off-by: liujing <liujing@cmss.chinamobile.com>
> 
> diff --git a/tools/bpf/bpftool/netlink_dumper.c b/tools/bpf/bpftool/netlink_dumper.c
> index 5f65140b003b..97e1e1dbc842 100644
> --- a/tools/bpf/bpftool/netlink_dumper.c
> +++ b/tools/bpf/bpftool/netlink_dumper.c
> @@ -45,7 +45,7 @@ static int do_xdp_dump_one(struct nlattr *attr, unsigned int ifindex,
>  	NET_START_OBJECT;
>  	if (name)
>  		NET_DUMP_STR("devname", "%s", name);
> -	NET_DUMP_UINT("ifindex", "(%d)", ifindex);
> +	NET_DUMP_UINT("ifindex", "(%u)", ifindex);
>  
>  	if (mode == XDP_ATTACHED_MULTI) {
>  		if (json_output) {
> @@ -168,7 +168,7 @@ int do_filter_dump(struct tcmsg *info, struct nlattr **tb, const char *kind,
>  		NET_START_OBJECT;
>  		if (devname[0] != '\0')
>  			NET_DUMP_STR("devname", "%s", devname);
> -		NET_DUMP_UINT("ifindex", "(%u)", ifindex);
> +		NET_DUMP_UINT("ifindex", "(%d)", ifindex);
>  		NET_DUMP_STR("kind", " %s", kind);
>  		ret = do_bpf_filter_dump(tb[TCA_OPTIONS]);
>  		NET_END_OBJECT_FINAL;


Thanks for this. The second chunk is not enough to fix the format
specifier cleanly, because NET_DUMP_UINT() may end up calling:

	jsonw_printf(self, "%"PRIu64, num);

So you probably need to add a NET_DUMP_INT() wrapper and call it here.

There's also another occurrence of the macro called on a signed
"ifindex" in net.c, in __show_dev_tc_bpf(), using "(%u)". Let's fix it
in the same patch, please?

Thanks,
Quentin

      parent reply	other threads:[~2024-11-28  9:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28  2:55 [PATCH] tools/bpf: bpftool:Fix the wrong format specifier liujing
2024-11-28  3:07 ` Alexei Starovoitov
2024-11-28  9:58 ` Quentin Monnet [this message]

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=0370e35c-a06b-40dd-90b4-50cc30db224c@kernel.org \
    --to=qmo@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liujing@cmss.chinamobile.com \
    --cc=martin.lau@linux.dev \
    --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