All of lore.kernel.org
 help / color / mirror / Atom feed
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
Cc: yatsenko@meta.com, tj@kernel.org, alan.maguire@oracle.com,
	bentiss@kernel.org, jikos@kernel.org, ameryhung@gmail.com,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, sched-ext@lists.linux.dev,
	martin.lau@kernel.org, yonghong.song@linux.dev, clm@meta.com
Subject: Re: [PATCH bpf-next v2 05/13] resolve_btfids: Support for KF_IMPLICIT_ARGS
Date: Fri, 16 Jan 2026 12:44:34 -0800	[thread overview]
Message-ID: <b15c25ab-2475-4129-bebe-db0c2f3a6aa8@linux.dev> (raw)
In-Reply-To: <d2f3a4f9eb847c74dbc7e584bfcff55bdde5c4c20382f77339299e1cc95e4102@mail.kernel.org>

On 1/16/26 12:39 PM, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> index 1fcf37af6764..b83316359cfd 100644
>> --- a/tools/bpf/resolve_btfids/main.c
>> +++ b/tools/bpf/resolve_btfids/main.c
> 
> [ ... ]
> 
>> +struct btf2btf_context {
>> +	struct btf *btf;
>> +	u32 *decl_tags;
>> +	u32 nr_decl_tags;
>> +	struct kfunc *kfuncs;
>> +	u32 nr_kfuncs;
>> +};
> 
> [ ... ]
> 
>> +static int collect_decl_tags(struct btf2btf_context *ctx)
>> +{
>> +	const u32 type_cnt = btf__type_cnt(ctx->btf);
>> +	struct btf *btf = ctx->btf;
>> +	const struct btf_type *t;
>> +	u32 *tags, *tmp;
>> +	u32 nr_tags = 0;
>> +
>> +	tags = malloc(type_cnt * sizeof(u32));
>> +	if (!tags)
>> +		return -ENOMEM;
> 
> [ ... ]
> 
>> +	tmp = realloc(tags, nr_tags * sizeof(u32));
>> +	if (!tmp) {
>> +		free(tags);
>> +		return -ENOMEM;
>> +	}
>> +
>> +	ctx->decl_tags = tmp;
>> +	ctx->nr_decl_tags = nr_tags;
>> +
>> +	return 0;
>> +}
> 
> [ ... ]
> 
>> +static s64 collect_kfuncs(struct object *obj, struct btf2btf_context *ctx)
>> +{
>> +	struct kfunc *kfunc, *kfuncs, *tmp;
> 
> [ ... ]
> 
>> +	kfuncs = malloc(ctx->nr_decl_tags * sizeof(*kfuncs));
>> +	if (!kfuncs)
>> +		return -ENOMEM;
> 
> [ ... ]
> 
>> +	tmp = realloc(kfuncs, nr_kfuncs * sizeof(*kfuncs));
>> +	if (!tmp) {
>> +		free(kfuncs);
>> +		return -ENOMEM;
>> +	}
>> +
>> +	ctx->kfuncs = tmp;
>> +	ctx->nr_kfuncs = nr_kfuncs;
>> +
>> +	return 0;
>> +}
>> +
>> +static int build_btf2btf_context(struct object *obj, struct btf2btf_context *ctx)
>> +{
>> +	int err;
>> +
>> +	ctx->btf = obj->btf;
>> +
>> +	err = collect_decl_tags(ctx);
>> +	if (err) {
>> +		pr_err("ERROR: resolve_btfids: failed to collect decl tags from BTF\n");
>> +		return err;
>> +	}
>> +
>> +	err = collect_kfuncs(obj, ctx);
>> +	if (err) {
>> +		pr_err("ERROR: resolve_btfids: failed to collect kfuncs from BTF\n");
>> +		return err;
>                   ^^^^
> 
> When collect_kfuncs() fails here, ctx->decl_tags has already been allocated
> by collect_decl_tags() but is not freed before returning. Should this error
> path call free(ctx->decl_tags)?
> 
>> +	}
>> +
>> +	return 0;
>> +}
> 
> [ ... ]
> 
>> +static int btf2btf(struct object *obj)
>> +{
>> +	struct btf2btf_context ctx = {};
>> +	int err;
>> +
>> +	err = build_btf2btf_context(obj, &ctx);
>> +	if (err)
>> +		return err;
>> +
>> +	for (u32 i = 0; i < ctx.nr_kfuncs; i++) {
>> +		struct kfunc *kfunc = &ctx.kfuncs[i];
>> +
>> +		if (!(kfunc->flags & KF_IMPLICIT_ARGS))
>> +			continue;
>> +
>> +		err = process_kfunc_with_implicit_args(&ctx, kfunc);
>> +		if (err)
>> +			return err;
>> +	}
>> +
>> +	return 0;
>> +}
>           ^^^^
> 
> ctx.decl_tags and ctx.kfuncs are allocated during build_btf2btf_context()
> but are never freed on any return path from btf2btf(). While this may be
> acceptable for a short-lived build tool where the OS reclaims memory on
> exit, should cleanup be added for consistency with the rest of the code
> which carefully frees allocations?

Right. I just noticed this after sending.

As AI mentioned, it's not a sever issue, but we should free everything
properly to be consistent.


> 
> 
> ---
> 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/21079944982


  reply	other threads:[~2026-01-16 20:44 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 20:16 [PATCH bpf-next v2 00/13] bpf: Kernel functions with KF_IMPLICIT_ARGS Ihor Solodrai
2026-01-16 20:16 ` [PATCH bpf-next v2 01/13] bpf: Refactor btf_kfunc_id_set_contains Ihor Solodrai
2026-01-16 20:16 ` [PATCH bpf-next v2 02/13] bpf: Introduce struct bpf_kfunc_meta Ihor Solodrai
2026-01-16 20:16 ` [PATCH bpf-next v2 03/13] bpf: Verifier support for KF_IMPLICIT_ARGS Ihor Solodrai
2026-01-20  0:03   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 04/13] resolve_btfids: Introduce finalize_btf() step Ihor Solodrai
2026-01-20  0:13   ` Eduard Zingerman
2026-01-20 18:11     ` Ihor Solodrai
2026-01-20 18:19       ` Eduard Zingerman
2026-01-20 18:35         ` Ihor Solodrai
2026-01-20 18:40           ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 05/13] resolve_btfids: Support for KF_IMPLICIT_ARGS Ihor Solodrai
2026-01-16 20:39   ` bot+bpf-ci
2026-01-16 20:44     ` Ihor Solodrai [this message]
2026-01-17  0:06   ` Andrii Nakryiko
2026-01-17  6:36     ` Ihor Solodrai
2026-01-20  0:24       ` Eduard Zingerman
2026-01-20  0:55   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 06/13] selftests/bpf: Add tests " Ihor Solodrai
2026-01-20  1:24   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 07/13] bpf: Migrate bpf_wq_set_callback_impl() to KF_IMPLICIT_ARGS Ihor Solodrai
2026-01-20  1:50   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 08/13] HID: Use bpf_wq_set_callback kernel function Ihor Solodrai
2026-01-16 20:16 ` [PATCH bpf-next v2 09/13] bpf: Migrate bpf_task_work_schedule_* kfuncs to KF_IMPLICIT_ARGS Ihor Solodrai
2026-01-20  1:52   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 10/13] bpf: Migrate bpf_stream_vprintk() " Ihor Solodrai
2026-01-20  1:53   ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 11/13] selftests/bpf: Migrate struct_ops_assoc test " Ihor Solodrai
2026-01-20  1:59   ` Eduard Zingerman
2026-01-20 18:20     ` Ihor Solodrai
2026-01-20 18:24       ` Eduard Zingerman
2026-01-16 20:16 ` [PATCH bpf-next v2 12/13] bpf: Remove __prog kfunc arg annotation Ihor Solodrai
2026-01-20  2:01   ` Eduard Zingerman
2026-01-16 20:17 ` [PATCH bpf-next v2 13/13] bpf,docs: Document KF_IMPLICIT_ARGS flag Ihor Solodrai
2026-01-20  1:49 ` [PATCH bpf-next v2 00/13] bpf: Kernel functions with KF_IMPLICIT_ARGS 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=b15c25ab-2475-4129-bebe-db0c2f3a6aa8@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=yatsenko@meta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.