Re: [PATCH v9 bpf-next 08/10] bpftool: add BTF dump "format meta" to dump header/metadata

[email protected]
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <da75355a80a85c4c1252b590c1fd550b799bdfdb8d2a7913a20a05e8e77b80b1@mail.kernel.org>
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 946612029dee..02f6ca4b3a51 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c

[ ... ]

> +	if (json_output) {
> +		jsonw_uint_field(json_wtr, "layout_len", hdr->layout_len);
> +		jsonw_uint_field(json_wtr, "layout_offset", hdr->layout_off);
                                              ^^^^^^^^^^^^^^

The other offset fields in this same JSON header object use the "_off"
suffix to match the struct btf_header field names:

    jsonw_uint_field(json_wtr, "type_off", hdr->type_off);
    jsonw_uint_field(json_wtr, "str_off", hdr->str_off);

The plain text path also uses "layout_off":

    printf("layout_len %-10u\nlayout_off %-10u\n", ...);

Should this be "layout_off" for consistency?

> +		jsonw_end_object(json_wtr);		/* end header object */
> +
> +		if (nr_kinds > 0) {
> +			jsonw_name(json_wtr, "layouts");
> +			jsonw_start_array(json_wtr);

When nr_kinds is 0, the "layouts" key is omitted entirely from the
JSON output.  Quentin Monnet raised this in v5 review and suggested
always emitting the array, even when empty:

https://lore.kernel.org/bpf/[email protected]/

An empty array would let JSON consumers loop over "layouts" without
first checking whether the key exists.  Was this intentionally left
conditional?

> +			for (i = 0; i < nr_kinds; i++) {

[ ... ]

> +			}
> +			jsonw_end_array(json_wtr);
> +		}
> +		jsonw_end_object(json_wtr);		/* end metadata object */

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22436234361

AI-authorship-score: low
AI-authorship-explanation: Multi-year review history (RFC to v9), domain-specific bpftool patterns, and iterative feedback-driven changes are consistent with human authorship.
issues-found: 2
issue-severity-score: low
issue-severity-explanation: JSON field naming inconsistency and an unaddressed maintainer review comment about conditional JSON array emission; neither causes crashes or incorrect behavior.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.