Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-15-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
88ed9184 e6ff1eed

+12 -7
+12 -7
tools/perf/util/pmu.c
··· 957 957 if (!pmu) 958 958 return NULL; 959 959 960 - INIT_LIST_HEAD(&pmu->format); 961 - INIT_LIST_HEAD(&pmu->aliases); 962 - INIT_LIST_HEAD(&pmu->caps); 963 960 pmu->name = strdup(name); 964 961 if (!pmu->name) 965 962 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 + 966 975 /* 967 976 * The pmu data we store & need consists of the pmu 968 977 * type value and format definitions. Load both right ··· 990 981 } 991 982 pmu->is_core = is_pmu_core(name); 992 983 pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core); 993 - 994 - /* Read type, and ensure that type value is successfully assigned (return 1) */ 995 - if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &type) != 1) 996 - goto err; 997 984 998 985 alias_name = pmu_find_alias_name(name); 999 986 if (alias_name) {