[RFC PATCH 24/25] perf stat: Add check to ensure correctness in platform that does not support hardware-grouping

weilin.wang
2023-09-25T06:21:25Z

Add check and return with -EINVAL when event json files do not support
hardware aware grouping so that the program could successfully fall back to
normal grouping without segfault.

Signed-off-by: Weilin Wang <weilin.wang@intel.com>
---
tools/perf/util/metricgroup.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 6a4404226..1c89c9371 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1684,6 +1684,8 @@ static int metricgroup__add_metric_event_callback(const struct pmu_event *pe,
struct metricgroup__add_metric_event_data *d = data;

if (!strcasecmp(pe->name, d->event_name)) {
+ if (!pe->counter)
+ return -EINVAL;
event = event_info__new(d->event_id, pe->pmu, pe->counter,
pe->taken_alone, /*free_counter=*/false);
if (!event)
--
2.39.3