aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <[email protected]>2020-05-20 11:20:06 -0700
committerArnaldo Carvalho de Melo <[email protected]>2020-05-28 10:03:28 -0300
commit908103991a9970a8e033e9f3aedd092a2c993f49 (patch)
treea599b9375635e764879ad56ac70754f1320dcd1e
parent4e21c13aca38b69c4470b68ef29d198802e7d74e (diff)
perf metricgroup: Use early return in add_metric
Use early return in metricgroup__add_metric and try to make the intent of the returns more intention revealing. Suggested-by: Jiri Olsa <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Cong Wang <[email protected]> Cc: Jin Yao <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Kim Phillips <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Clarke <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Srikar Dronamraju <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vince Weaver <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/metricgroup.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 0798658592d9..70f3f92a3262 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -527,7 +527,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
{
struct pmu_events_map *map = perf_pmu__find_map(NULL);
struct pmu_event *pe;
- int i, ret = -EINVAL;
+ int i, ret;
+ bool has_match = false;
if (!map)
return 0;
@@ -535,17 +536,23 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
for (i = 0; ; i++) {
pe = &map->table[i];
- if (!pe->name && !pe->metric_group && !pe->metric_name)
+ if (!pe->name && !pe->metric_group && !pe->metric_name) {
+ /* End of pmu events. */
+ if (!has_match)
+ return -EINVAL;
break;
+ }
if (!pe->metric_expr)
continue;
if (match_metric(pe->metric_group, metric) ||
match_metric(pe->metric_name, metric)) {
-
+ has_match = true;
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
if (!strstr(pe->metric_expr, "?")) {
ret = __metricgroup__add_metric(events, group_list, pe, 1);
+ if (ret)
+ return ret;
} else {
int j, count;
@@ -556,14 +563,15 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
* those events to group_list.
*/
- for (j = 0; j < count; j++)
+ for (j = 0; j < count; j++) {
ret = __metricgroup__add_metric(events, group_list, pe, j);
+ if (ret)
+ return ret;
+ }
}
- if (ret == -ENOMEM)
- break;
}
}
- return ret;
+ return 0;
}
static int metricgroup__add_metric_list(const char *list, struct strbuf *events,