diff mbox series

[v1,01/11] perf report: Smatch: Fix potential NULL pointer dereference

Message ID 20190702103420.27540-2-leo.yan@linaro.org
State New
Headers show
Series perf: Fix errors detected by Smatch | expand

Commit Message

Leo Yan July 2, 2019, 10:34 a.m. UTC
Based on the following report from Smatch, fix the potential
NULL pointer dereference check.

  tools/perf/builtin-report.c:304
  process_read_event() error: we previously assumed 'evsel' could be null (see line 301)

tools/perf/builtin-report.c
301                 const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
302                 int err = perf_read_values_add_value(&rep->show_threads_values,
303                                            event->read.pid, event->read.tid,
304                                            evsel->idx,
                                               ^^^^^^^
305                                            name,
306                                            event->read.value);

This patch checks if 'evsel' is NULL pointer then pass UINT64_MAX as idx
parameter.

Signed-off-by: Leo Yan <leo.yan@linaro.org>

---
 tools/perf/builtin-report.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 91c40808380d..a894ce7cd04e 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -299,10 +299,10 @@  static int process_read_event(struct perf_tool *tool,
 
 	if (rep->show_threads) {
 		const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
+		int idx = evsel ? evsel->idx : INT_MAX;
 		int err = perf_read_values_add_value(&rep->show_threads_values,
 					   event->read.pid, event->read.tid,
-					   evsel->idx,
-					   name,
+					   idx, name,
 					   event->read.value);
 
 		if (err)