Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+7 -1
+7 -1
tools/perf/util/evsel.c
··· 589 589 { 590 590 char bf[128]; 591 591 592 + if (!evsel) 593 + goto out_unknown; 594 + 592 595 if (evsel->name) 593 596 return evsel->name; 594 597 ··· 631 628 632 629 evsel->name = strdup(bf); 633 630 634 - return evsel->name ?: "unknown"; 631 + if (evsel->name) 632 + return evsel->name; 633 + out_unknown: 634 + return "unknown"; 635 635 } 636 636 637 637 const char *perf_evsel__group_name(struct perf_evsel *evsel)