Commit 0b0e0d74 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Greg Kroah-Hartman

perf evsel: Make perf_evsel__name() accept a NULL argument

[ Upstream commit fdbdd7e8 ]

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: default avatarLeo 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 380ca130
...@@ -584,6 +584,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel) ...@@ -584,6 +584,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
{ {
char bf[128]; char bf[128];
if (!evsel)
goto out_unknown;
if (evsel->name) if (evsel->name)
return evsel->name; return evsel->name;
...@@ -620,7 +623,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel) ...@@ -620,7 +623,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
evsel->name = strdup(bf); 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) const char *perf_evsel__group_name(struct perf_evsel *evsel)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment