perf metrics: Avoid segv with --topdown
Ian Rogers
reviewerPATCH 1/1 perf metrics: Avoid segv with --topdown
Some metrics may not have a metric_group which can result in segvs with "perf stat --topdown". Add a condition for the no metric_group case.
Fixes 1647cd5b8802 ("perf stat: Implement --topdown using json metrics")
Reported-by Kan Liang <[email protected]>
Signed-off-by Ian Rogers <[email protected]>
--- tools/perf/util/metricgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/metricgroup.c +1 -1
@@ -1672,7 +1672,7 @@ static int metricgroup__topdown_max_level_callback(const struct pmu_metric *pm, {unsigned int *max_level = data;unsigned int level; -const char *p =strstr (pm->metric_group,"TopdownL" ); +const char *p =strstr (pm->metric_group ?:"" ,"TopdownL" );if (!p || p[8 ] =='\0' )return 0 ;
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
Quoted 7 lines · Ian Rogers
Some metrics may not have a
metric_groupwhich can result in segvs with "perf stat --topdown". Add a condition for the nometric_groupcase.Fixes 1647cd5b8802 ("perf stat: Implement --topdown using json metrics")Reported-by Kan Liang <[email protected]>Signed-off-by Ian Rogers <[email protected]>
Tested-by Kan Liang <[email protected]>
Thanks,
Kan
Quoted 17 lines
--- tools/perf/util/metricgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/metricgroup.c +1
-1@@ -1672,7 +1672,7 @@ static int metricgroup__topdown_max_level_callback(const struct pmu_metric *pm, {unsigned int *max_level = data;unsigned int level; -const char *p =strstr (pm->metric_group,"TopdownL" ); +const char *p =strstr (pm->metric_group ?:"" ,"TopdownL" );if (!p || p[8 ] =='\0' )return 0 ;