perf evsel: Make perf_evsel__name() accept a NULL argument [Linux 4.4.187]

This Linux kernel change "perf evsel: Make perf_evsel__name() accept a NULL argument" is included in the Linux 4.4.187 release. This change is authored by Arnaldo Carvalho de Melo <acme [at] redhat.com> on Mon Jun 17 14:32:53 2019 -0300. The commit for this change in Linux stable tree is b5f997a (patch) which is from upstream commit fdbdd7e. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream fdbdd7e.

perf evsel: Make perf_evsel__name() accept a NULL argument

[ Upstream commit fdbdd7e8580eac9bdafa532746c865644d125e34 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>

There are 8 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/perf/util/evsel.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 97fde92..a8507fe 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -491,6 +491,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
 {
    char bf[128];

+   if (!evsel)
+       goto out_unknown;
+
    if (evsel->name)
        return evsel->name;

@@ -527,7 +530,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)

Leave a Reply

Your email address will not be published. Required fields are marked *