On Mon, Sep 28, 2026 at 4:47 AM Luis Vieira <[email protected]> wrote: > > btf_dump_type_data_check_zero() uses -ENODATA to indicate that a value > is zero. The array path handles this sentinel correctly, but the struct > and union path compares the return value against positive ENODATA. > > As a result, the member loop returns after examining its first member. > A nested struct or union whose first member is zero can therefore be > treated as entirely zero even when a later member is non-zero. > > Compare against -ENODATA so zero members are skipped while looking for > a non-zero member. Add a regression test with a nested struct whose > first member is zero and second member is non-zero. > > Signed-off-by: Luis Vieira <[email protected]> > --- > tools/lib/bpf/btf_dump.c | 2 +- > tools/testing/selftests/bpf/prog_tests/btf_dump.c | 5 +++++ > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c > index fa995c02a170..dbf9f17e4b37 100644 > --- a/tools/lib/bpf/btf_dump.c > +++ b/tools/lib/bpf/btf_dump.c > @@ -2474,7 +2474,7 @@ static int btf_dump_type_data_check_zero(struct > btf_dump *d, > bit_sz = btf_member_bitfield_size(t, i); > err = btf_dump_type_data_check_zero(d, mtype, > m->type, data + moffset / 8, > moffset % 8, > bit_sz); > - if (err != ENODATA) > + if (err != -ENODATA) > return err; > } > return -ENODATA; > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c > b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > index fe04a955d46c..dd1241fcdb01 100644 > --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c > +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > @@ -886,6 +886,11 @@ static void test_btf_dump_struct_data(struct btf *btf, > struct btf_dump *d, > "(union bpf_iter_link_info){.map = > (struct){.map_fd = (__u32)1,},.cgroup = (struct){.order = (enum > bpf_cgroup_iter_order)BPF_CGROUP_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},.task > = (struct){.tid = (__u32)1,.pid = (__u32)1,},}", > { .cgroup = { .order = 1, .cgroup_fd = 1, }}); > > + /* nested structs with zero first member and non-zero second member */ > + TEST_BTF_DUMP_DATA(btf, d, "union", str, union bpf_iter_link_info, > BTF_F_COMPACT, > + "(union bpf_iter_link_info){.cgroup = > (struct){.cgroup_fd = (__u32)1,},.task = (struct){.pid = (__u32)1,},}", > + { .cgroup = { .cgroup_fd = 1 }}); > +
can you please split selftest into a separate patch and send as v2? the fix makes sense, that missing - is definitely a typo we missed pw-bot: cr > /* struct skb with nested structs/unions; because type output is so > * complex, we don't do a string comparison, just verify we return > * the type size as the amount of data displayed. > > --- > base-commit: ea9358e1270ab2c3ba6f36bd9bdda68617665516 > change-id: 20260928-libbpf-btf-enodata-fix-ac6381645ab8 > > Best regards, > -- > Luis Vieira <[email protected]> >

