Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3806304ybi; Mon, 29 Jul 2019 13:00:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOMT/9vHFkvfItUVbJQJSB693RDujR78ILVFC6fDg3KDKbCHH4CCl2q/eECJcHvoIdFeiw X-Received: by 2002:a62:1597:: with SMTP id 145mr36944607pfv.180.1564430455401; Mon, 29 Jul 2019 13:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430455; cv=none; d=google.com; s=arc-20160816; b=I9xhhSzlRrA/lfnTC/n5/yxOMhdgs23y/9DykoEV3QQWsCqlrxmrNPtIuuQusVgO5R HvXRHmgWJRfdhr2LYbcZkWZUxJWE2j12HCqULfdL3qiZ9J2XM6UsnWzVGLHkhyJ/yoZ9 beS3fO0AK32zMd3jDP7hpkcS7LFCqHlL8FWIoYZ2WSNu7m39oaAMyAAdXtwx3dM2zL7z izdNCZe8BQUAnma/N4Ynjrbms9vcUsUk3tXHU169+NBDOwIFeIWUTeVmGJaJAvRp5oci /2JrpSQ5qePo5IBfWCg82J4iaM1IguGzTT0TYNt2armXBq+hFvubWSELdqWsRlAfe16K 99Ag== 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=RDI8mwhznnbMkNpWamgICAcUYigM3q8E/knRKeGQ24U=; b=M9D/ADRLYr9WxmV5RbgtEumZXrbihg58IR3MYeyW2buT39KqEtX5BJcgG8GbCZ+Q1o qYc1RZ5sNDwZJyVbhWojVlO5PUQ3lKYhGx+FJbPBVELh0M5r8rnmBvhyYetpNcYxtm0w RlvBC5LB7145DVYylBscvSlOFfiB3Xd4ArGS+DB8ihsj4P75zKjjEwKBIIOYT8zXK4w8 ull5Vg6u2mRVrfEuYVB0Rc7pruGtag3v0J5ZGs2uxBOGL9+bX9z4Td0x2/6A00ooA2YB z8FsfleT8MeMb0DV6k/N50lJ18QoiFHGETlOXak5Yig1095bQArAq0IFtqrZY0gy1IpY kcBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GIJBWt8K; 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 c189si39542823pfa.110.2019.07.29.13.00.40; Mon, 29 Jul 2019 13:00:55 -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=GIJBWt8K; 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 S2404346AbfG2T7Z (ORCPT + 99 others); Mon, 29 Jul 2019 15:59:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:45172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390861AbfG2TxH (ORCPT ); Mon, 29 Jul 2019 15:53:07 -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 6EA40217D7; Mon, 29 Jul 2019 19:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429985; bh=sFfn2UZdTEp+YrDjG7uK+E7T6yPIR+C9ODctvnIzeqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GIJBWt8KBhnaTgg92tnCAhkfMATK+SwYDxjvm3S+lqV6GaF/ykWUSq/DK2vK4XH4R y+d7P8XlmmrcOC/lhCwJHqRBjOqtuODPVEgZtqCRDyhdx602iCJygyAhoOaLisWEEI OzQYRqbeSc6rljNwsoSLef04MCKE8hqBPrtQsbLY= 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 5.2 122/215] perf top: Fix potential NULL pointer dereference detected by the smatch tool Date: Mon, 29 Jul 2019 21:21:58 +0200 Message-Id: <20190729190800.312232580@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 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