From: Will Deacon <will@kernel.org>
To: Zongmin Zhou <min_halo@163.com>
Cc: kvm@vger.kernel.org, julien.thierry.kdev@gmail.com,
Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: Re: [PATCH kvmtool] arm64: Fix resource leaks in find_pmu_cpumask()
Date: Fri, 31 Jul 2026 18:04:07 +0100 [thread overview]
Message-ID: <amzVh6ILi4rd6PwU@google.com> (raw)
In-Reply-To: <20260723090413.52218-1-min_halo@163.com>
On Thu, Jul 23, 2026 at 05:04:13PM +0800, Zongmin Zhou wrote:
> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>
> Close file descriptors on read_file() failure and close the directory
> stream before returning from the function.
>
> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
> ---
> arm64/pmu.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arm64/pmu.c b/arm64/pmu.c
> index 78c15f1..b4d7605 100644
> --- a/arm64/pmu.c
> +++ b/arm64/pmu.c
> @@ -75,7 +75,7 @@ static int find_pmu_cpumask(struct kvm *kvm, cpumask_t *cpumask)
> unsigned long val;
> ssize_t fd_sz;
> int fd, ret;
> - DIR *dir;
> + DIR *dir = NULL;
>
> memset(buf, 0, sizeof(buf));
>
> @@ -109,6 +109,7 @@ static int find_pmu_cpumask(struct kvm *kvm, cpumask_t *cpumask)
> fd_sz = read_file(fd, cpulist, PAGE_SIZE);
> if (fd_sz < 0) {
> pmu_id = -errno;
> + close(fd);
> goto out_free;
> }
> close(fd);
Seems a bit grotty to have identical calls to close() on the success and
failure paths.
> @@ -142,6 +143,7 @@ static int find_pmu_cpumask(struct kvm *kvm, cpumask_t *cpumask)
> fd_sz = read_file(fd, buf, PMU_ID_MAXLEN - 1);
> if (fd_sz < 0) {
> pmu_id = -errno;
> + close(fd);
> goto out_free;
> }
> close(fd);
Same here...
Will
prev parent reply other threads:[~2026-07-31 17:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 9:04 [PATCH kvmtool] arm64: Fix resource leaks in find_pmu_cpumask() Zongmin Zhou
2026-07-31 17:04 ` Will Deacon [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=amzVh6ILi4rd6PwU@google.com \
--to=will@kernel.org \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=min_halo@163.com \
--cc=zhouzongmin@kylinos.cn \
/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