mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 18:55:12 +00:00
perf pmu: Fix a few potential fd leaks
Ensure fd is closed on error paths. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Gaosheng Cui <cuigaosheng1@huawei.com> Cc: German Gomez <german.gomez@arm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20230406065224.2553640-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
3d88aec0d4
commit
0ea8920e86
@ -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);
|
||||
file = fdopen(fd, "r");
|
||||
if (!file)
|
||||
if (fd == -1)
|
||||
continue;
|
||||
file = fdopen(fd, "r");
|
||||
if (!file) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fgets(value, sizeof(value), file) ||
|
||||
(perf_pmu__new_caps(&pmu->caps, name, value) < 0)) {
|
||||
|
Loading…
Reference in New Issue
Block a user