Skip to content

Commit 88ed918

Browse files
captain5050acmel
authored andcommitted
perf pmu: Scan type early to fail an invalid PMU quickly
Scan sysfs PMU's type early so that format and aliases aren't attempted to be loaded if the PMU name is invalid. This is the case for event_pmu tokens in parse-events.y where a wildcard name is first assumed to be a PMU name. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Gaosheng Cui <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e6ff1ee commit 88ed918

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tools/perf/util/pmu.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,12 +957,21 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
957957
if (!pmu)
958958
return NULL;
959959

960-
INIT_LIST_HEAD(&pmu->format);
961-
INIT_LIST_HEAD(&pmu->aliases);
962-
INIT_LIST_HEAD(&pmu->caps);
963960
pmu->name = strdup(name);
964961
if (!pmu->name)
965962
goto err;
963+
964+
/*
965+
* Read type early to fail fast if a lookup name isn't a PMU. Ensure
966+
* that type value is successfully assigned (return 1).
967+
*/
968+
if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &type) != 1)
969+
goto err;
970+
971+
INIT_LIST_HEAD(&pmu->format);
972+
INIT_LIST_HEAD(&pmu->aliases);
973+
INIT_LIST_HEAD(&pmu->caps);
974+
966975
/*
967976
* The pmu data we store & need consists of the pmu
968977
* type value and format definitions. Load both right
@@ -982,10 +991,6 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
982991
pmu->is_core = is_pmu_core(name);
983992
pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core);
984993

985-
/* Read type, and ensure that type value is successfully assigned (return 1) */
986-
if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &type) != 1)
987-
goto err;
988-
989994
alias_name = pmu_find_alias_name(name);
990995
if (alias_name) {
991996
pmu->alias_name = strdup(alias_name);

0 commit comments

Comments
 (0)