perf pmu: Use relative path in perf_pmu__caps_parse()

Likewise, it needs to traverse the pmu/caps directory, let's use
openat() with the dirfd instead of open() using the absolute path.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230331202949.810326-2-namhyung@kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim
2023-04-04 13:23:58 -03:00
committed by Arnaldo Carvalho de Melo
parent e293a5e816
commit b39094d37d
+6 -4
View File
@@ -1804,6 +1804,7 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
char caps_path[PATH_MAX];
DIR *caps_dir;
struct dirent *evt_ent;
int caps_fd;
if (pmu->caps_initialized)
return pmu->nr_caps;
@@ -1822,18 +1823,19 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu)
if (!caps_dir)
return -EINVAL;
caps_fd = dirfd(caps_dir);
while ((evt_ent = readdir(caps_dir)) != NULL) {
char path[PATH_MAX + NAME_MAX + 1];
char *name = evt_ent->d_name;
char value[128];
FILE *file;
int fd;
if (!strcmp(name, ".") || !strcmp(name, ".."))
continue;
snprintf(path, sizeof(path), "%s/%s", caps_path, name);
file = fopen(path, "r");
fd = openat(caps_fd, name, O_RDONLY);
file = fdopen(fd, "r");
if (!file)
continue;