Re: [PATCH v9 bpf-next 03/10] libbpf: use layout to compute an unknown kind size
| Newsgroups | org.kernel.vger.dwarves,org.kernel.vger.bpf |
|---|---|
| Message-ID | <965519c1d6e765ce216b16bcc8831a5ec17e8b1185968f3291670a2cc75032e3@mail.kernel.org> |
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -355,7 +355,36 @@ static int btf_parse_layout_sec(struct btf *btf)
> return 0;
> }
>
> +/* for unknown kinds, consult kind layout. */
> +static int btf_type_size_unknown(const struct btf *btf, const struct btf_type *t)
> +{
> + __u32 layout_kinds = btf->hdr.layout_len / sizeof(struct btf_layout);
> + int size = sizeof(struct btf_type);
> + struct btf_layout *l = btf->layout;
> + __u16 vlen = btf_vlen(t);
> + __u32 kind = btf_kind(t);
[ ... ]
> + size += l[kind].info_sz;
> + size += vlen * l[kind].elem_sz;
> +
> + return size;
> +}
In the v8 review, Andrii suggested simplifying this to a single return
statement without the intermediate size variable:
return sizeof(struct btf_type) + l[kind].info_sz + vlen * l[kind].elem_sz;
The size variable is initialized at declaration and only modified at
the very end, so it could be dropped. Was this intentionally kept,
or just missed during the v9 update?
https://lore.kernel.org/bpf/CAEf4BzbsLMgRuJz0PGDojZG32G0GQcSKnt4F9CVVROLPXHY+TA@mail.gmail.com/
---
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: Code follows established kernel BTF patterns with domain-specific naming, and the author has an extensive lore patch history for this subsystem.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Unaddressed style suggestion from libbpf maintainer to simplify size computation to a single return statement.