From: Hungyu Lin <dennylin0707@gmail.com>
To: qmo@kernel.org, bpf@vger.kernel.org
Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net,
linux-kernel@vger.kernel.org, Hungyu Lin <dennylin0707@gmail.com>
Subject: [RFC PATCH bpf-next] bpftool: avoid sign extension in unsigned enum JSON dumps
Date: Fri, 30 Oct 2026 09:09:13 +0000 [thread overview]
Message-ID: <20261030090913.76944-1-dennylin0707@gmail.com> (raw)
The BTF enum value is stored in a signed 32-bit field even when the
enum is unsigned. Passing it directly to jsonw_uint_field(), which
takes a uint64_t, sign-extends values with bit 31 set. For example,
0xffffffffU is printed as 18446744073709551615 instead of 4294967295
by bpftool -j btf dump.
Cast the value to __u32 before widening it, matching the conversion
already used for plain-text output.
Fixes: c93cc69004df ("bpftool: add ability to dump BTF types")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.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 abd661db91e6..385521e6b028 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -482,7 +482,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
if (btf_kflag(t))
jsonw_int_field(w, "val", v->val);
else
- jsonw_uint_field(w, "val", v->val);
+ jsonw_uint_field(w, "val", (__u32)v->val);
jsonw_end_object(w);
} else {
if (btf_kflag(t))
base-commit: 7101b10cf281f629ac58c99697ca6f6d082b99a7
--
2.43.0
next reply other threads:[~2026-10-30 9:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 9:09 Hungyu Lin [this message]
2026-10-30 10:26 ` 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=20261030090913.76944-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=qmo@kernel.org \
/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®