public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpftool: Fix incorrect format specifier for var
@ 2024-11-11  2:48 Luo Yifan
  2024-11-11 13:08 ` Quentin Monnet
  2024-11-12  4:08 ` Andrii Nakryiko
  0 siblings, 2 replies; 7+ messages in thread
From: Luo Yifan @ 2024-11-11  2:48 UTC (permalink / raw)
  To: qmo, ast, daniel, andrii, martin.lau, eddyz87, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, Luo Yifan

In cases where the SIGNED condition is met, the variable var is still
used as an unsigned long long. Therefore, the %llu format specifier
should be used to avoid incorrect data print. This patch fixes it.

Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
---
 tools/bpf/bpftool/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 7d2af1ff3..ff58ff85e 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -283,7 +283,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 				jsonw_end_object(w);
 			} else {
 				if (btf_kflag(t))
-					printf("\n\t'%s' val=%lldLL", name,
+					printf("\n\t'%s' val=%lluLL", name,
 					       (unsigned long long)val);
 				else
 					printf("\n\t'%s' val=%lluULL", name,
-- 
2.27.0




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] bpftool: Fix incorrect format specifier for var
  2024-11-11  2:48 [PATCH] bpftool: Fix incorrect format specifier for var Luo Yifan
@ 2024-11-11 13:08 ` Quentin Monnet
  2024-11-12  1:44   ` Luo Yifan
  2024-11-12  4:08 ` Andrii Nakryiko
  1 sibling, 1 reply; 7+ messages in thread
From: Quentin Monnet @ 2024-11-11 13:08 UTC (permalink / raw)
  To: Luo Yifan, ast, daniel, andrii, martin.lau, eddyz87, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel

2024-11-11 10:48 UTC+0800 ~ Luo Yifan <luoyifan@cmss.chinamobile.com>
> In cases where the SIGNED condition is met, the variable var is still
> used as an unsigned long long. Therefore, the %llu format specifier
> should be used to avoid incorrect data print. This patch fixes it.
> 
> Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
> ---
>  tools/bpf/bpftool/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 7d2af1ff3..ff58ff85e 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -283,7 +283,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  				jsonw_end_object(w);
>  			} else {
>  				if (btf_kflag(t))
> -					printf("\n\t'%s' val=%lldLL", name,
> +					printf("\n\t'%s' val=%lluLL", name,
>  					       (unsigned long long)val);
>  				else
>  					printf("\n\t'%s' val=%lluULL", name,


Hi, I don't think your change is correct, it seems to me that we do want
to make the distinction between the signed and unsigned version here (as
for all the other enum cases in the function). What are you trying to
address, did you find a bug in the output or a warning during compilation?

Quentin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] bpftool: Fix incorrect format specifier for var
  2024-11-11 13:08 ` Quentin Monnet
@ 2024-11-12  1:44   ` Luo Yifan
  0 siblings, 0 replies; 7+ messages in thread
From: Luo Yifan @ 2024-11-12  1:44 UTC (permalink / raw)
  To: qmo
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, luoyifan, martin.lau, sdf, song,
	yonghong.song

Hello, this is not a bug, but a minor change to eliminate a static checker warning. Since the var parameter has been cast to unsigned long long, the corresponding format specifier should be %llu instead of %lld.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] bpftool: Fix incorrect format specifier for var
  2024-11-11  2:48 [PATCH] bpftool: Fix incorrect format specifier for var Luo Yifan
  2024-11-11 13:08 ` Quentin Monnet
@ 2024-11-12  4:08 ` Andrii Nakryiko
  2024-11-12  7:37   ` [PATCH] bpftool: Cast variable `var` to long long Luo Yifan
  1 sibling, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2024-11-12  4:08 UTC (permalink / raw)
  To: Luo Yifan
  Cc: qmo, ast, daniel, andrii, martin.lau, eddyz87, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, bpf,
	linux-kernel

On Sun, Nov 10, 2024 at 6:48 PM Luo Yifan <luoyifan@cmss.chinamobile.com> wrote:
>
> In cases where the SIGNED condition is met, the variable var is still
> used as an unsigned long long. Therefore, the %llu format specifier
> should be used to avoid incorrect data print. This patch fixes it.
>
> Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
> ---
>  tools/bpf/bpftool/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 7d2af1ff3..ff58ff85e 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -283,7 +283,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>                                 jsonw_end_object(w);
>                         } else {
>                                 if (btf_kflag(t))
> -                                       printf("\n\t'%s' val=%lldLL", name,
> +                                       printf("\n\t'%s' val=%lluLL", name,
>                                                (unsigned long long)val);

the fix should be casting to (long long) instead

pw-bot: cr

>                                 else
>                                         printf("\n\t'%s' val=%lluULL", name,
> --
> 2.27.0
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] bpftool: Cast variable `var` to long long
  2024-11-12  4:08 ` Andrii Nakryiko
@ 2024-11-12  7:37   ` Luo Yifan
  2024-11-12  9:33     ` Quentin Monnet
  2024-11-13 20:20     ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 7+ messages in thread
From: Luo Yifan @ 2024-11-12  7:37 UTC (permalink / raw)
  To: andrii.nakryiko, qmo
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, luoyifan, martin.lau, sdf, song,
	yonghong.song

When the SIGNED condition is met, the variable `var` should be cast to
`long long` instead of `unsigned long long`.

Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
---
 tools/bpf/bpftool/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 547c1ccdc..d005e4fd6 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -289,7 +289,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 			} else {
 				if (btf_kflag(t))
 					printf("\n\t'%s' val=%lldLL", name,
-					       (unsigned long long)val);
+					       (long long)val);
 				else
 					printf("\n\t'%s' val=%lluULL", name,
 					       (unsigned long long)val);
-- 
2.27.0




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] bpftool: Cast variable `var` to long long
  2024-11-12  7:37   ` [PATCH] bpftool: Cast variable `var` to long long Luo Yifan
@ 2024-11-12  9:33     ` Quentin Monnet
  2024-11-13 20:20     ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 7+ messages in thread
From: Quentin Monnet @ 2024-11-12  9:33 UTC (permalink / raw)
  To: Luo Yifan, andrii.nakryiko
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, martin.lau, sdf, song, yonghong.song

2024-11-12 15:37 UTC+0800 ~ Luo Yifan <luoyifan@cmss.chinamobile.com>
> When the SIGNED condition is met, the variable `var` should be cast to
> `long long` instead of `unsigned long long`.
> 
> Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>

Looks good this time, thank you!

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] bpftool: Cast variable `var` to long long
  2024-11-12  7:37   ` [PATCH] bpftool: Cast variable `var` to long long Luo Yifan
  2024-11-12  9:33     ` Quentin Monnet
@ 2024-11-13 20:20     ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-13 20:20 UTC (permalink / raw)
  To: Luo Yifan
  Cc: andrii.nakryiko, qmo, andrii, ast, bpf, daniel, eddyz87, haoluo,
	john.fastabend, jolsa, kpsingh, linux-kernel, martin.lau, sdf,
	song, yonghong.song

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue, 12 Nov 2024 15:37:01 +0800 you wrote:
> When the SIGNED condition is met, the variable `var` should be cast to
> `long long` instead of `unsigned long long`.
> 
> Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com>
> ---
>  tools/bpf/bpftool/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
  - bpftool: Cast variable `var` to long long
    https://git.kernel.org/bpf/bpf-next/c/b7b31f184f88

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-11-13 20:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-11  2:48 [PATCH] bpftool: Fix incorrect format specifier for var Luo Yifan
2024-11-11 13:08 ` Quentin Monnet
2024-11-12  1:44   ` Luo Yifan
2024-11-12  4:08 ` Andrii Nakryiko
2024-11-12  7:37   ` [PATCH] bpftool: Cast variable `var` to long long Luo Yifan
2024-11-12  9:33     ` Quentin Monnet
2024-11-13 20:20     ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox