perf evsel: Make perf_evsel__name() accept a NULL argument
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Jun 2019 17:32:53 +0000 (14:32 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Jun 2019 18:57:20 +0000 (15:57 -0300)
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>
tools/perf/util/evsel.c

index 0f506f10ecf05417485fbd273d7a31cd892cd5a7..04c4ed1573cb9e6fa28d047783d37f3847a8ba58 100644 (file)
@@ -589,6 +589,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
 {
        char bf[128];
 
+       if (!evsel)
+               goto out_unknown;
+
        if (evsel->name)
                return evsel->name;
 
@@ -628,7 +631,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
 
        evsel->name = strdup(bf);
 
-       return evsel->name ?: "unknown";
+       if (evsel->name)
+               return evsel->name;
+out_unknown:
+       return "unknown";
 }
 
 const char *perf_evsel__group_name(struct perf_evsel *evsel)