From: Jiri Olsa <olsajiri@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@arm.com>,
Suzuki Poulouse <suzuki.poulose@arm.com>,
Sean Christopherson <seanjc@google.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
Rob Herring <robh@kernel.org>, Leo Yan <leo.yan@linaro.org>,
German Gomez <german.gomez@arm.com>,
Jing Zhang <renyu.zj@linux.alibaba.com>,
Gaosheng Cui <cuigaosheng1@huawei.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] perf pmu: Fix a few potential fd leaks
Date: Thu, 6 Apr 2023 22:42:25 +0100 [thread overview]
Message-ID: <ZC88waWWdSDKIuyI@krava> (raw)
In-Reply-To: <20230406065224.2553640-2-irogers@google.com>
On Wed, Apr 05, 2023 at 11:52:24PM -0700, Ian Rogers wrote:
> Ensure fd is closed on error paths.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
nice catch
Acked-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirka
> ---
> tools/perf/util/pmu.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 96ef317bac41..9eedbfc9e863 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -494,9 +494,13 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head)
> continue;
>
> fd = openat(dirfd, name, O_RDONLY);
> + if (fd == -1) {
> + pr_debug("Cannot open %s\n", name);
> + continue;
> + }
> file = fdopen(fd, "r");
> if (!file) {
> - pr_debug("Cannot open %s\n", name);
> + close(fd);
> continue;
> }
>
> @@ -1882,9 +1886,13 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
> continue;
>
> fd = openat(caps_fd, name, O_RDONLY);
> + if (fd == -1)
> + continue;
> file = fdopen(fd, "r");
> - if (!file)
> + if (!file) {
> + close(fd);
> continue;
> + }
>
> if (!fgets(value, sizeof(value), file) ||
> (perf_pmu__new_caps(&pmu->caps, name, value) < 0)) {
> --
> 2.40.0.348.gf938b09366-goog
>
next prev parent reply other threads:[~2023-04-06 21:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 6:52 [PATCH v3 1/2] perf pmu: Make parser reentrant Ian Rogers
2023-04-06 6:52 ` [PATCH v3 2/2] perf pmu: Fix a few potential fd leaks Ian Rogers
2023-04-06 20:19 ` Namhyung Kim
2023-04-06 21:09 ` Arnaldo Carvalho de Melo
2023-04-06 21:33 ` Ian Rogers
2023-04-06 21:42 ` Jiri Olsa [this message]
2023-04-06 21:41 ` [PATCH v3 1/2] perf pmu: Make parser reentrant Jiri Olsa
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=ZC88waWWdSDKIuyI@krava \
--to=olsajiri@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=cuigaosheng1@huawei.com \
--cc=german.gomez@arm.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=renyu.zj@linux.alibaba.com \
--cc=robh@kernel.org \
--cc=seanjc@google.com \
--cc=suzuki.poulose@arm.com \
/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.