Skip to content

Commit

Permalink
perf metricgroup: Return error code from metricgroup__add_metric_sys_…
Browse files Browse the repository at this point in the history
…event_iter()

The error code is not set at all in the sys event iter function.

This may lead to an uninitialized value of "ret" in
metricgroup__add_metric() when no CPU metric is added.

Fix by properly setting the error code.

It is not necessary to init "ret" to 0 in metricgroup__add_metric(), as
if we have no CPU or sys event metric matching, then "has_match" should
be 0 and "ret" is set to -EINVAL.

However gcc cannot detect that it may not have been set after the
map_for_each_metric() loop for CPU metrics, which is strange.

Fixes: be335ec ("perf metricgroup: Support adding metrics for system PMUs")
Signed-off-by: John Garry <[email protected]>
Acked-by: Ian Rogers <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
John Garry authored and acmel committed Jun 19, 2021
1 parent fc96ec4 commit fe7a98b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/perf/util/metricgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,16 +1073,18 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,

ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids);
if (ret)
return ret;
goto out;

ret = resolve_metric(d->metric_no_group,
d->metric_list, NULL, d->ids);
if (ret)
return ret;
goto out;

*(d->has_match) = true;

return *d->ret;
out:
*(d->ret) = ret;
return ret;
}

static int metricgroup__add_metric(const char *metric, bool metric_no_group,
Expand Down

0 comments on commit fe7a98b

Please sign in to comment.