From patchwork Tue Jul 9 18:31:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168756 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896125ilk; Tue, 9 Jul 2019 11:31:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKfvvxXuJteLDAR//nIdoS9d8h47fl89v6OJ5WkeHoh0gaH9bNS1NnyZGurx4V19W5+bxJ X-Received: by 2002:a17:902:7c90:: with SMTP id y16mr34343764pll.238.1562697117685; Tue, 09 Jul 2019 11:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697117; cv=none; d=google.com; s=arc-20160816; b=rWKYyYp656xTLdYLU5pia+Zjrx2c2qthBLLvh6TrFRtvBoqdWtAb9vlSK6QMSxhhFn o5Y4xx8khLyztY1/z76yb58NSUJ9Awf5d6MwyEQvtCsDsnVy+Dk/VSCtVGOlYzrty366 0T3xtyAjXDljbm7fRfA5LSIxojKvTbs08HCT6UdYmCSHJdVBxyEhaDUky0Ra6kfqdlWA 6xjIeA9+3dcm2aQoERKNALto95yPrfFRvsCEXjJsWvYpGxDVfRWxqz+M6Sxm4RqNtLjK Luvh901j7A5O+rJBI/gSVybn1Z2D+NpjQZs2KC9pSP8+oWhDf6T8M083GbzsGgSWPa4N dGKA== 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=I8XknWA6iYpcZTURSxx8UuYj2uePVMSg9pXuAkUxRas=; b=YS0J/DkzvzBfpeYp+6vPCDIoqvk1TKzAa3aIpGupJuSxnp9ThzJkDjBlKgGtXnh0rI HIqAopZ91wN4Mrznq+WYJ7IRLLqL/w/AGa9G1AOCeZRw8zkKy6sDNUQFTNVBF+3392x0 bga6XnRSX9imJblhhB1r+77p1RXLqxzw1MW1Dy72EmCrq/g1d1r0ejBES+i0M+QCDr50 fc+48pkGlKsJbK3N1+NatC4pm7P1y1K7KkTo8xqKv8HRxaA8Fy15CWex5zocIasR/HNU F2kz8QEnbSrmBowKnUBVD3yGSzNrxszQ8fSmLXhEVarh/kmKZ44f/MWi8357BBzk4P3h 0mlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WttUJ7bQ; 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 t7si16515593plr.27.2019.07.09.11.31.57; Tue, 09 Jul 2019 11:31:57 -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=WttUJ7bQ; 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 S1729052AbfGISb4 (ORCPT + 30 others); Tue, 9 Jul 2019 14:31:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:53156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfGISb4 (ORCPT ); Tue, 9 Jul 2019 14:31:56 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 34BE4216FD; Tue, 9 Jul 2019 18:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697114; bh=/r3kNfehywaYBWJZ3L/w2X8MX2iuc/x3OcDG99w2lbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WttUJ7bQp7Fy1xQD0OuMxektnM/uEuj/z08KGlKdD1Q4WBH3eV2aMY66Ed3df4/Qn oZT+CRuUjbD9KpDjbUM7Oo36DSzK6WqhnBw3MvFN3e77ioNz9+Mhrq/Vq26rIxZrAw /ntkinYg+LWlj8Uosc/3N7EXKLg/A+IxlxNMKjyE= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 03/25] perf top: Fix potential NULL pointer dereference detected by the smatch tool Date: Tue, 9 Jul 2019 15:31:04 -0300 Message-Id: <20190709183126.30257-4-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan 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 --- tools/perf/builtin-top.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 6d40a4ef58c5..b46b3c9f57a0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -101,7 +101,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; @@ -110,6 +110,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; @@ -226,7 +228,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; @@ -234,6 +236,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);