Skip to content

Commit fdbdd7e

Browse files
committed
perf evsel: Make perf_evsel__name() accept a NULL argument
In which case it simply returns "unknown", like when it can't figure out the evsel->name value. This makes this code more robust and fixes a problem in 'perf trace' where a NULL evsel was being passed to a routine that only used the evsel for printing its name when a invalid syscall id was passed. Reported-by: Leo Yan <leo.yan@linaro.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-f30ztaasku3z935cn3ak3h53@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 016f327 commit fdbdd7e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎tools/perf/util/evsel.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
589589
{
590590
char bf[128];
591591

592+
if (!evsel)
593+
goto out_unknown;
594+
592595
if (evsel->name)
593596
return evsel->name;
594597

@@ -628,7 +631,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
628631

629632
evsel->name = strdup(bf);
630633

631-
return evsel->name ?: "unknown";
634+
if (evsel->name)
635+
return evsel->name;
636+
out_unknown:
637+
return "unknown";
632638
}
633639

634640
const char *perf_evsel__group_name(struct perf_evsel *evsel)

0 commit comments

Comments
 (0)