BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Maguire" <alan.maguire@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v15 bpf-next 8/9] selftests/bpf: Test kind encoding/decoding
Date: Thu, 13 Aug 2026 22:35:10 +0000	[thread overview]
Message-ID: <20260813223510.7E7EE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260324174450.1570809-9-alan.maguire@oracle.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The BTF object `btf` is leaked on early error paths.
--

--- Patch [8]: [PATCH v15 bpf-next 8/9] selftests/bpf: Test kind encoding/decoding ---
commit 2e5fe50dd1168fa6e0f69edd9f780d42539e7151
Author: Alan Maguire <alan.maguire@oracle.com>

selftests/bpf: Test kind encoding/decoding

This commit adds tests to verify that btf__new_empty_opts() correctly adds
layouts for all supported kinds. It also ensures that parsing of a BTF
containing unrecognized kinds can still succeed.

> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_kind.c b/tools/testing/selftests/bpf/prog_tests/btf_kind.c
> new file mode 100644
> index 0000000000000..64ceac1d999e6
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_kind.c
> @@ -0,0 +1,226 @@
[ ... ]
> +static void test_btf_kind_encoding(void)
> +{
> +	LIBBPF_OPTS(btf_new_opts, opts);
> +	const struct btf_header *hdr;
> +	const void *raw_btf;
> +	struct btf *btf;
> +	__u32 raw_size;
> +
> +	opts.add_layout = true;
> +	btf = btf__new_empty_opts(&opts);
> +	if (!ASSERT_OK_PTR(btf, "btf_new"))
> +		return;
> +
> +	raw_btf = btf__raw_data(btf, &raw_size);
> +	if (!ASSERT_OK_PTR(raw_btf, "btf__raw_data"))
> +		return;

[Severity: Medium]
Does this early return leak the btf object allocated just above by 
btf__new_empty_opts()? It looks like btf__free(btf) is skipped if
btf__raw_data() fails.

[ ... ]
> +void test_btf_kind_decoding(void)
> +{
> +	char btf_kind_file1[] = "/tmp/test_btf_kind.XXXXXX";
> +	char btf_kind_file2[] = "/tmp/test_btf_kind.XXXXXX";
> +	char btf_kind_file3[] = "/tmp/test_btf_kind.XXXXXX";
> +	struct btf *btf = NULL, *new_btf = NULL;
> +	__s32 int_id, unrec_id, id, id2;
> +	LIBBPF_OPTS(btf_new_opts, opts);
> +	struct btf_layout *l;
> +	struct btf_header *hdr;
> +	const void *raw_btf;
> +	struct btf_type *t;
> +	void *new_raw_btf;
> +	void *str_data;
> +	__u32 raw_size;
> +
> +	opts.add_layout = true;
> +	btf = btf__new_empty_opts(&opts);
> +	if (!ASSERT_OK_PTR(btf, "btf_new"))
> +		return;
> +
> +	int_id = btf__add_int(btf, "test_char", 1, BTF_INT_CHAR);
> +	if (!ASSERT_GT(int_id, 0, "add_int_id"))
> +		return;

[Severity: Medium]
Will this direct return bypass the cleanup block at the end of the function
and leak the btf object? 

There are several other similar return statements following this one. Should 
these early failure paths use goto out to ensure btf__free(btf) is called?

> +
> +	/*
> +	 * Create our type with unrecognized kind by adding a typedef kind
> +	 * we will overwrite it with our unrecognized kind value.
> +	 */
> +	unrec_id = btf__add_typedef(btf, "unrec_kind", int_id);
> +	if (!ASSERT_GT(unrec_id, 0, "add_unrec_id"))
> +		return;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260324174450.1570809-1-alan.maguire@oracle.com?part=8

  reply	other threads:[~2026-08-13 22:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 17:44 [PATCH v15 bpf-next 0/9] Add BTF layout to BTF Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 1/9] btf: Add BTF kind layout encoding to UAPI Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 2/9] libbpf: Support layout section handling in BTF Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 3/9] libbpf: Use layout to compute an unknown kind size Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 4/9] libbpf: Add layout encoding support Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 5/9] libbpf: BTF validation can use layout for unknown kinds Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 6/9] libbpf: Support sanitization of BTF layout for older kernels Alan Maguire
2026-03-24 18:55   ` bot+bpf-ci
2026-03-25 17:39     ` Alan Maguire
2026-03-25 18:52       ` Alexei Starovoitov
2026-03-24 17:44 ` [PATCH v15 bpf-next 7/9] btf: support kernel parsing of BTF with layout info Alan Maguire
2026-03-24 17:44 ` [PATCH v15 bpf-next 8/9] selftests/bpf: Test kind encoding/decoding Alan Maguire
2026-08-13 22:35   ` sashiko-bot [this message]
2026-03-24 17:44 ` [PATCH v15 bpf-next 9/9] kbuild, bpf: Specify "layout" optional feature Alan Maguire

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=20260813223510.7E7EE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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