Skip to content

Commit 33321a0

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Avoid an uninitialized read when using fake PMUs
With a fake_pmu the pmu_info isn't populated by perf_pmu__check_alias. In this case, don't try to copy the uninitialized values to the evsel. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20200826042910.1902374-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 313146a commit 33321a0

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

tools/perf/util/parse-events.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,19 +1534,23 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
15341534
evsel = __add_event(list, &parse_state->idx, &attr, true,
15351535
get_config_name(head_config), pmu,
15361536
&config_terms, auto_merge_stats, NULL);
1537-
if (evsel) {
1538-
evsel->unit = info.unit;
1539-
evsel->scale = info.scale;
1540-
evsel->per_pkg = info.per_pkg;
1541-
evsel->snapshot = info.snapshot;
1542-
evsel->metric_expr = info.metric_expr;
1543-
evsel->metric_name = info.metric_name;
1544-
evsel->pmu_name = name ? strdup(name) : NULL;
1545-
evsel->use_uncore_alias = use_uncore_alias;
1546-
evsel->percore = config_term_percore(&evsel->config_terms);
1547-
}
1548-
1549-
return evsel ? 0 : -ENOMEM;
1537+
if (!evsel)
1538+
return -ENOMEM;
1539+
1540+
evsel->pmu_name = name ? strdup(name) : NULL;
1541+
evsel->use_uncore_alias = use_uncore_alias;
1542+
evsel->percore = config_term_percore(&evsel->config_terms);
1543+
1544+
if (parse_state->fake_pmu)
1545+
return 0;
1546+
1547+
evsel->unit = info.unit;
1548+
evsel->scale = info.scale;
1549+
evsel->per_pkg = info.per_pkg;
1550+
evsel->snapshot = info.snapshot;
1551+
evsel->metric_expr = info.metric_expr;
1552+
evsel->metric_name = info.metric_name;
1553+
return 0;
15501554
}
15511555

15521556
int parse_events_multi_pmu_add(struct parse_events_state *parse_state,

0 commit comments

Comments
 (0)