Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3100239ybi; Thu, 18 Jul 2019 21:02:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoc2oaqG6Q14T7soMd5H6ZG8qrEmaYPSqFguBhL4ugdZRfBPgGwbkMDlfktG2MkfCnWdbT X-Received: by 2002:a17:90a:30e4:: with SMTP id h91mr53049417pjb.37.1563508939900; Thu, 18 Jul 2019 21:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508939; cv=none; d=google.com; s=arc-20160816; b=OGQVohzbDWnwBEsts/ydUwsZt+j5nfwPqLuSDYNJQ02cDT8YxtmPnE4kmTRK5qoeTg LELVl2TwjpNfB6XtqBHncPOl+rKaRr7xE7WrzE3QMlJj/GmaKMW+i4xOxLwDgErjC5lW IDH6sAMWbgDARcfdUR7CeSffZfCjoQ4pg3N6LlBMhltaam0OAE+qwdYmaIHCuOaFvQ1W jmRjreW97yi3GGF4MPXt7ozKoHveD+U2G6bza4oVtHgW7fXMrhimNyF5yWsmaPX8QgMw ddkViCxKbUPUEtr7ixGz2KeY9qX9HUFrp8OM3Elp9HdJqf7Kftj3sKZMkx/5CkOgFcqN 53Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mP+S/iVL0VuEWgvcYNCE1bAfVmxxJqbRP8LkFA9m/y8=; b=R137NeH8haswlOro3vXfMySw51kPdAarjWixFHMBwGVVV4O+3HohknRxhwM+qXVTxX Xfyea3Ne5Qmh+uDyCzJ8jvGR0MxzP9X5wNT45moHQgk20DgDjdlXCsfQ1R18McqI/lYH XsIIbRV5L9xLZj4Bg3sobT/FnQJiUPDS3ml1Xb+pBpGdFFPzaFI8ANnVnnBpemSrvLSd j6BDVNdOwmvvfZ3W++YAsiTW2esFRC2d8Ny2LmIdH5G3BrKoXVHymNbP5HNqLK83ZOjG P3J2HvTfeVMxtUcTpRPiDVYAy2ZTIUamXBy7Adr1NolS7wZ7pimh7hoMNzVv4R6prOpe c3sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mfNl9RHU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j185si102685pge.91.2019.07.18.21.02.04; Thu, 18 Jul 2019 21:02:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mfNl9RHU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729294AbfGSEBB (ORCPT + 99 others); Fri, 19 Jul 2019 00:01:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbfGSEAz (ORCPT ); Fri, 19 Jul 2019 00:00:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F331521873; Fri, 19 Jul 2019 04:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508854; bh=ph2Z+/2HkFD1e0+2qCkiIDRQNVc3eTu28TAQv8mOx90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mfNl9RHU8XtACDWUM4G5M+moYaB3YQCaDyxNlCf9C/ZRW0MVjAV//Lu3G+sAM5dVM JgEKEKbetRC9LsHK5U03+Q3bSSa4h2cozP4eAnBMwU5IwUHGvsLAM2j07PHvvjr7Ih FUI1Dys+wSLAbuucLYbNM5t+5l2nCFPk5UDcjfTk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Leo Yan , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Alexey Budankov , Alexios Zavras , Andi Kleen , Changbin Du , "David S . Miller" , Davidlohr Bueso , Eric Saint-Etienne , Jin Yao , Konstantin Khlebnikov , Mathieu Poirier , Namhyung Kim , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Gleixner , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.2 125/171] perf top: Fix potential NULL pointer dereference detected by the smatch tool Date: Thu, 18 Jul 2019 23:55:56 -0400 Message-Id: <20190719035643.14300-125-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan [ Upstream commit 111442cfc8abdeaa7ec1407f07ef7b3e5f76654e ] Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/builtin-top.c:109 perf_top__parse_source() warn: variable dereferenced before check 'he' (see line 103) tools/perf/builtin-top.c:233 perf_top__show_details() warn: variable dereferenced before check 'he' (see line 228) tools/perf/builtin-top.c 101 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) 102 { 103 struct perf_evsel *evsel = hists_to_evsel(he->hists); ^^^^ 104 struct symbol *sym; 105 struct annotation *notes; 106 struct map *map; 107 int err = -1; 108 109 if (!he || !he->ms.sym) 110 return -1; This patch moves the values assignment after validating pointer 'he'. Signed-off-by: Leo Yan Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Alexios Zavras Cc: Andi Kleen Cc: Changbin Du Cc: David S. Miller Cc: Davidlohr Bueso Cc: Eric Saint-Etienne Cc: Jin Yao Cc: Konstantin Khlebnikov Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Rasmus Villemoes Cc: Song Liu Cc: Suzuki Poulouse Cc: Thomas Gleixner Cc: Thomas Richter Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190702103420.27540-4-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-top.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 466621cd1017..8a9ff4b11df0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -100,7 +100,7 @@ static void perf_top__resize(struct perf_top *top) static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) { - struct perf_evsel *evsel = hists_to_evsel(he->hists); + struct perf_evsel *evsel; struct symbol *sym; struct annotation *notes; struct map *map; @@ -109,6 +109,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) if (!he || !he->ms.sym) return -1; + evsel = hists_to_evsel(he->hists); + sym = he->ms.sym; map = he->ms.map; @@ -225,7 +227,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, static void perf_top__show_details(struct perf_top *top) { struct hist_entry *he = top->sym_filter_entry; - struct perf_evsel *evsel = hists_to_evsel(he->hists); + struct perf_evsel *evsel; struct annotation *notes; struct symbol *symbol; int more; @@ -233,6 +235,8 @@ static void perf_top__show_details(struct perf_top *top) if (!he) return; + evsel = hists_to_evsel(he->hists); + symbol = he->ms.sym; notes = symbol__annotation(symbol); -- 2.20.1