Thread (46 messages) flat view 46 messages, 4 authors, 1d ago

Re: [PATCH v2 bpf-next 04/18] selftests/bpf: Test helper support for BTF_KIND_LOC[_PARAM|_PROTO|SEC]

From: sashiko-bot@kernel.org
Date: 2026-09-01 17:06:36
Also in: bpf

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incorrect format specifiers `%d` used for unsigned `__u32` variables when formatting BTF_KIND_LOC_PARAM and BTF_KIND_LOCSEC.
--

commit 775b46a26f73799ae68ad5737114128e343d1d80
Author: Alan Maguire [off-list ref]

selftests/bpf: Test helper support for BTF_KIND_LOC[_PARAM|_PROTO|SEC]

Add support to dump, encode and validate new location-related kinds.
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 1c1c2c26690a7..6065ee4ba00a6 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -203,6 +206,37 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
 		fprintf(out, " type_id=%u component_idx=%d",
 			t->type, btf_decl_tag(t)->component_idx);
 		break;
+	case BTF_KIND_LOC_PARAM: {
+		struct btf_loc_param *p = btf_loc_param(t);
+		__u32 *v = (__u32 *)(p + 1);
+
+		fprintf(out, " size=%d flags=0x%x vlen=%u", t->size, p->flags, vlen);
[Severity: Low]
Does this format string interpret the unsigned __u32 t->size as a signed
integer? If t->size exceeds 2^31-1, it could be printed as a negative number
here, which differs from how other BTF kinds format their sizes using %u.
+		for (i = 0; i < vlen; i++, v++) {
+			if (p->flags & BTF_LOC_PARAM_SIGNED)
+				fprintf(out, "\n\tvalue=%d", (__s32)*v);
+			else
+				fprintf(out, "\n\tvalue=%u", *v);
+		}
+		break;
+	}
[ ... ]
+	case BTF_KIND_LOCSEC: {
+		const struct btf_loc *l = btf_locsec_locs(t);
+
+		fprintf(out, " vlen=%u", vlen);
+		for (i = 0; i < vlen; i++, l++) {
+			fprintf(out, "\n\tfunc_type_id=%u loc_proto_type_id=%u offset=%d",
+				l->func, l->loc_proto, l->offset);
[Severity: Low]
Similarly, l->offset is defined as __u32 in struct btf_loc but is formatted
with %d. Should this use %u as well to prevent large offsets from appearing
negative in the output?
+		}
+		break;
+	}
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901165757.801449-1-alan.maguire@oracle.com?part=4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help