From: Leo Yan <leo....@linaro.org>

[ Upstream commit 7a6d49dc8cad8fa1f3d63994102af8f9ae9c859f ]

Based on the following report from Smatch, fix the potential NULL
pointer dereference check.

  tools/perf/builtin-trace.c:1044
  thread_trace__new() error: we previously assumed 'ttrace' could be
  null (see line 1041).

  tools/perf/builtin-trace.c
  1037 static struct thread_trace *thread_trace__new(void)
  1038 {
  1039         struct thread_trace *ttrace =  zalloc(sizeof(struct 
thread_trace));
  1040
  1041         if (ttrace)
  1042                 ttrace->files.max = -1;
  1043
  1044         ttrace->syscall_stats = intlist__new(NULL);
               ^^^^^^^^
  1045
  1046         return ttrace;
  1047 }

Signed-off-by: Leo Yan <leo....@linaro.org>
Acked-by: Jiri Olsa <jo...@kernel.org>
Cc: Adrian Hunter <adrian.hun...@intel.com>
Cc: Alexander Shishkin <alexander.shish...@linux.intel.com>
Cc: Alexey Budankov <alexey.budan...@linux.intel.com>
Cc: Alexios Zavras <alexios.zav...@intel.com>
Cc: Andi Kleen <a...@linux.intel.com>
Cc: Changbin Du <changbin...@intel.com>
Cc: David S. Miller <da...@davemloft.net>
Cc: Davidlohr Bueso <d...@stgolabs.net>
Cc: Eric Saint-Etienne <eric.saint.etie...@oracle.com>
Cc: Jin Yao <yao....@linux.intel.com>
Cc: Konstantin Khlebnikov <khlebni...@yandex-team.ru>
Cc: Mathieu Poirier <mathieu.poir...@linaro.org>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Rasmus Villemoes <li...@rasmusvillemoes.dk>
Cc: Song Liu <songliubrav...@fb.com>
Cc: Suzuki Poulouse <suzuki.poul...@arm.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Thomas Richter <tmri...@linux.ibm.com>
Cc: linux-arm-ker...@lists.infradead.org
Link: http://lkml.kernel.org/r/20190702103420.27540-6-leo....@linaro.org
[ Just made it look like other tools/perf constructors, same end result ]
Signed-off-by: Arnaldo Carvalho de Melo <a...@redhat.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 tools/perf/builtin-trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f5b3a1e9c1dd..aca22e8f6947 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -998,10 +998,10 @@ static struct thread_trace *thread_trace__new(void)
 {
        struct thread_trace *ttrace =  zalloc(sizeof(struct thread_trace));
 
-       if (ttrace)
+       if (ttrace) {
                ttrace->files.max = -1;
-
-       ttrace->syscall_stats = intlist__new(NULL);
+               ttrace->syscall_stats = intlist__new(NULL);
+       }
 
        return ttrace;
 }
-- 
2.20.1

Reply via email to