linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	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 18:09:29 -0300	[thread overview]
Message-ID: <ZC81CTH/VayirB5z@kernel.org> (raw)
In-Reply-To: <20230406065224.2553640-2-irogers@google.com>

Em Wed, Apr 05, 2023 at 11:52:24PM -0700, Ian Rogers escreveu:
> Ensure fd is closed on error paths.

Was this reported by Jiri?

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  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
> 

-- 

- Arnaldo

  parent reply	other threads:[~2023-04-06 21:09 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 [this message]
2023-04-06 21:33     ` Ian Rogers
2023-04-06 21:42   ` Jiri Olsa
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=ZC81CTH/VayirB5z@kernel.org \
    --to=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=jolsa@kernel.org \
    --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 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).