Linux kbuild/kconfig development
 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,
	nathan@kernel.org, nsc@kernel.org
Cc: bpf@vger.kernel.org, linux-kbuild@vger.kernel.org,
	martin.lau@kernel.org, yonghong.song@linux.dev, clm@meta.com
Subject: Re: [PATCH bpf-next v1] resolve_btfids: Implement --patch_btfids
Date: Tue, 30 Dec 2025 16:28:31 -0800	[thread overview]
Message-ID: <6b24678f-b2eb-4139-8fe1-0834c8c8b75a@linux.dev> (raw)
In-Reply-To: <bba828ccd8d2ef3871375809d56c8d66c161bc453f03df80090dc03cf31f50aa@mail.kernel.org>

On 12/30/25 4:26 PM, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> index 2cbc252259be..1269efa06853 100644
>> --- a/tools/bpf/resolve_btfids/main.c
>> +++ b/tools/bpf/resolve_btfids/main.c
> 
> [ ... ]
> 
>> +static int patch_btfids(const char *btfids_path, const char *elf_path)
>> +{
>> +	Elf_Scn *scn = NULL;
>> +	FILE *btfids_file;
>> +	size_t shdrstrndx;
>> +	int fd, err = -1;
>> +	Elf_Data *data;
>> +	struct stat st;
>> +	GElf_Shdr sh;
>> +	char *name;
>> +	Elf *elf;
>> +
>> +	elf_version(EV_CURRENT);
>> +
>> +	fd = open(elf_path, O_RDWR, 0666);
>> +	if (fd < 0) {
>> +		pr_err("FAILED to open %s: %s\n", elf_path, strerror(errno));
>> +		return -1;
>> +	}
>> +
>> +	elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>> +	if (!elf) {
>> +		close(fd);
>> +		pr_err("FAILED cannot create ELF descriptor: %s\n", elf_errmsg(-1));
>> +		return -1;
>> +	}
> 
> [ ... ]
> 
>> +	err = 0;
>> +out:
>> +	elf_end(elf);
>> +	return err;
>> +}
> 
> Should the file descriptor fd be closed here? Looking at elf_collect() and its
> cleanup in main(), the pattern is to call elf_end() and then close(fd)
> separately. Without close(fd), error paths that reach 'goto out' after
> successful open() and elf_begin() will leak the file descriptor.

Correct. I missed close(fd) on the happy path.

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


      reply	other threads:[~2025-12-31  0:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31  0:07 [PATCH bpf-next v1] resolve_btfids: Implement --patch_btfids Ihor Solodrai
2025-12-31  0:26 ` bot+bpf-ci
2025-12-31  0:28   ` Ihor Solodrai [this message]

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=6b24678f-b2eb-4139-8fe1-0834c8c8b75a@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@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=linux-kbuild@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --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