Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3812679ybi; Mon, 29 Jul 2019 13:07:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5kZgUnbrYMGTOEQghSmdvGhc9n/r6MkKCxZ+lFIWyfs5GfuIVzewpZcUkfjy2w118RpH6 X-Received: by 2002:a65:5b8e:: with SMTP id i14mr104444570pgr.188.1564430825698; Mon, 29 Jul 2019 13:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430825; cv=none; d=google.com; s=arc-20160816; b=oBnJ8s15jFUr2JpA13Gb7yiuxBqIqs47bZgbr5gbup8eygiTSxBl/OdBh5Ho1dT7+u zBVAjGVrHWw/F0z0fMjg5oUOA/Q028/0+i9g9uPQSYOKZ9232GKJtcJ27QBjTt/Yejdp H7qf5GnElG0cZB5HvkNucAnofQhgl5HaS4oLXTsXMgsGtD1pn9pT+tMAlnBt9wEE9+7m pTt8IdxYd0w6okSitCsxE0gklIGkqUPLo4PIlzVoqdllkG88aS3WJS+TCmfmZTLkc/Cs u7aADJEha1VloQbf2HSgMJzB5nOIAmLvTi26UEBtmo5usOdTlaaEOoiyU8RKjkpXaPMO cSpg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NxjzgHcRA0YUDSxklKVqgoLzxZny7E6585bGhm1q+GA=; b=z1SvoTqyc/tleMStyIOsBpYVPNHjWP64yDOAJvT4suDbyZDGbou18PfaZttfW0C3Zc XoipvSIjCTAJxmMNIwiM0EXJ9+2CKITdUVwOFtXj2yD18bXljhH7qs0GKdd8oyvE/nt7 7rpiALZLPbsDNsNX4/VtphetZiFuE5ky91AdabCTVTiIx4gyZcxN/PJFGX2fmRzznQZU B/bn1+MlA4jBQxy0pSess261aN6x06NcxJVZ1gjD19m86cZgRPUtORbSohZ5H4FB/yNH OUDYAioaS2W/d77eKfnC6dYBgKoGBS2Gc6SRnE9DPxlG5JZCCbs4FYfah+DWjUYmOvVw zoGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v0HAlwpj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si29947172pgj.347.2019.07.29.13.06.50; Mon, 29 Jul 2019 13:07:05 -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=v0HAlwpj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389515AbfG2Tmg (ORCPT + 99 others); Mon, 29 Jul 2019 15:42:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:58362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389501AbfG2Tmc (ORCPT ); Mon, 29 Jul 2019 15:42:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CC5AF20C01; Mon, 29 Jul 2019 19:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429352; bh=3UEydif8h+lKxicNWgQImmEghmKUxXP1kN5j02nXTBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0HAlwpjZDoel1ZIJ+NHAxIL2Fx629X3xdfarXjR3cG/GsS90nzYBdeiGaWCG/Vqz JM4KE9A0jzdhY98QwPjhyZ0tQtJLxzYM6iCuuPboDu1ifhBygXgDCO6Xc2nI1/kS+4 VCqMIPJFIUfvWipd7ikuQprGZM8HKOSpT4OfJFTo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, 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 4.19 069/113] perf top: Fix potential NULL pointer dereference detected by the smatch tool Date: Mon, 29 Jul 2019 21:22:36 +0200 Message-Id: <20190729190711.996881254@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 33eefc33e0ea..d0733251a386 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -99,7 +99,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; @@ -108,6 +108,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; @@ -224,7 +226,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; @@ -232,6 +234,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