mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps
@ 2026-10-31 22:36 Hungyu Lin
  2026-10-31 22:52 ` Alexei Starovoitov
  2026-10-31 23:09 ` bot+bpf-ci
  0 siblings, 2 replies; 3+ messages in thread
From: Hungyu Lin @ 2026-10-31 22:36 UTC (permalink / raw)
  To: qmo, bpf; +Cc: ast, daniel, andrii, yonghong.song, linux-kernel, Hungyu Lin

When an enum64 data value does not match a named enumerator,
btf_dumper_enum64() always prints it as signed. Unsigned values with
bit 63 set therefore appear negative in BTF-formatted map dump and
lookup output, in both plain and JSON modes. For example,
0x8000000000000001 is printed as -9223372036854775807 instead of
9223372036854775809.

Choose the numeric writer according to the enum's signedness. Keep
signed values and named enumerators unchanged.

Fixes: 58a53978fdf6 ("bpftool: Add btf enum64 support")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 tools/bpf/bpftool/btf_dumper.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 3267163119dc..88c0da29f246 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -204,7 +204,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
 		}
 	}
 
-	jsonw_int(d->jw, value);
+	if (btf_kflag(t))
+		jsonw_int(d->jw, value);
+	else
+		jsonw_uint(d->jw, value);
 	return 0;
 }
 

base-commit: eaae576c34d7e001767b6845a5950b0b8db3e68a
-- 
2.43.0


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

end of thread, other threads:[~2026-10-31 23:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 22:36 [PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps Hungyu Lin
2026-10-31 22:52 ` Alexei Starovoitov
2026-10-31 23:09 ` bot+bpf-ci

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®