From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: bot+bpf-ci@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, akpm@linux-foundation.org,
nathan@kernel.org, nsc@kernel.org, tj@kernel.org,
void@manifault.com, arighi@nvidia.com, changwoo@igalia.com,
shuah@kernel.org, nick.desaulniers+lkml@gmail.com,
morbo@google.com, justinstitt@google.com,
alan.maguire@oracle.com, dolinux.peng@gmail.com
Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
martin.lau@kernel.org, clm@meta.com
Subject: Re: [PATCH bpf-next v3 2/6] resolve_btfids: Factor out load_btf()
Date: Fri, 5 Dec 2025 15:12:01 -0800 [thread overview]
Message-ID: <fb8c16dc-07ee-48bb-a370-0a4931dbba08@linux.dev> (raw)
In-Reply-To: <e7478657b0308d8c4c16f5f412e92a3dbf565b0777424bd6d163d1d8288cf10a@mail.kernel.org>
On 12/5/25 2:57 PM, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> index 164f0c941f04..b4caae1170dd 100644
>> --- a/tools/bpf/resolve_btfids/main.c
>> +++ b/tools/bpf/resolve_btfids/main.c
>
> [ ... ]
>
>> @@ -529,16 +532,10 @@ static int symbols_collect(struct object *obj)
>> return 0;
>> }
>>
>> -static int symbols_resolve(struct object *obj)
>> +static int load_btf(struct object *obj)
>> {
>> - int nr_typedefs = obj->nr_typedefs;
>> - int nr_structs = obj->nr_structs;
>> - int nr_unions = obj->nr_unions;
>> - int nr_funcs = obj->nr_funcs;
>> - struct btf *base_btf = NULL;
>> - int err, type_id;
>> - struct btf *btf;
>> - __u32 nr_types;
>> + struct btf *base_btf = NULL, *btf = NULL;
>> + int err;
>>
>> if (obj->base_btf_path) {
>> base_btf = btf__parse(obj->base_btf_path, NULL);
>> err = libbpf_get_error(base_btf);
>> if (err) {
>> pr_err("FAILED: load base BTF from %s: %s\n",
>> obj->base_btf_path, strerror(-err));
>> - return -1;
>> + goto out_err;
>> }
>> }
>>
>> btf = btf__parse_split(obj->btf_path ?: obj->path, base_btf);
>> err = libbpf_get_error(btf);
>> if (err) {
>> pr_err("FAILED: load BTF from %s: %s\n",
>> obj->btf_path ?: obj->path, strerror(-err));
>> - goto out;
>> + goto out_err;
>> }
>>
>> + obj->base_btf = base_btf;
>> + obj->btf = btf;
>> +
>> + return 0;
>> +
>> +out_err:
>> + btf__free(base_btf);
>> + btf__free(btf);
>> + return err;
>
> Can btf__free() safely handle ERR_PTR values here?
>
> When btf__parse() fails on line 541, it returns ERR_PTR(-err), and
> libbpf_get_error() extracts the error code, but base_btf still holds
> the ERR_PTR value. The error path then calls btf__free(base_btf)
> where base_btf is ERR_PTR rather than NULL or a valid pointer.
>
> The same issue occurs if btf__parse_split() fails on line 550, where
> btf contains ERR_PTR when btf__free(btf) is called.
>
> In the old code at symbols_resolve(), if base_btf was ERR_PTR, the
> function would return -1 immediately without calling btf__free(),
> avoiding this issue. The new error handling with goto out_err changes
> this behavior.
That's a good observation. Interesting that AI noticed this only on
third try, probably due to changes in prompts.
btf__free() checks for error values [1], so this is not an issue.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/btf.c?h=v6.18#n968
>
>> +}
>> +
>> +static int symbols_resolve(struct object *obj)
>> +{
>> + int nr_typedefs = obj->nr_typedefs;
>> + int nr_structs = obj->nr_structs;
>> + int nr_unions = obj->nr_unions;
>> + int nr_funcs = obj->nr_funcs;
>> + struct btf *btf = obj->btf;
>> + int err, type_id;
>> + __u32 nr_types;
>> +
>> err = -1;
>> nr_types = btf__type_cnt(btf);
>
> [ ... ]
>
>
> ---
> 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/19978081551
next prev parent reply other threads:[~2025-12-05 23:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 22:30 [PATCH bpf-next v3 0/6] resolve_btfids: Support for BTF modifications Ihor Solodrai
2025-12-05 22:30 ` [PATCH bpf-next v3 1/6] resolve_btfids: Rename object btf field to btf_path Ihor Solodrai
2025-12-12 7:10 ` Eduard Zingerman
2025-12-05 22:30 ` [PATCH bpf-next v3 2/6] resolve_btfids: Factor out load_btf() Ihor Solodrai
2025-12-05 22:57 ` bot+bpf-ci
2025-12-05 23:12 ` Ihor Solodrai [this message]
2025-12-05 23:18 ` Chris Mason
2025-12-12 7:10 ` Eduard Zingerman
2025-12-05 22:30 ` [PATCH bpf-next v3 3/6] resolve_btfids: Introduce enum btf_id_kind Ihor Solodrai
2025-12-12 7:09 ` Eduard Zingerman
2025-12-05 22:30 ` [PATCH bpf-next v3 4/6] lib/Kconfig.debug: Set the minimum required pahole version to v1.22 Ihor Solodrai
2025-12-05 22:49 ` bot+bpf-ci
2025-12-05 22:51 ` Ihor Solodrai
2025-12-06 0:32 ` Andrii Nakryiko
2025-12-06 0:58 ` Ihor Solodrai
2025-12-12 7:09 ` Eduard Zingerman
2025-12-12 17:26 ` Alan Maguire
2025-12-05 22:30 ` [PATCH bpf-next v3 5/6] selftests/bpf: Run resolve_btfids only for relevant .test.o objects Ihor Solodrai
2025-12-05 22:35 ` [PATCH bpf-next v3 6/6] resolve_btfids: change in-place update with raw binary output Ihor Solodrai
2025-12-06 1:13 ` Andrii Nakryiko
2025-12-06 1:37 ` Ihor Solodrai
2025-12-12 7:08 ` Eduard Zingerman
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=fb8c16dc-07ee-48bb-a370-0a4931dbba08@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=arighi@nvidia.com \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=dolinux.peng@gmail.com \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nsc@kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
--cc=yonghong.song@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;
as well as URLs for NNTP newsgroup(s).