Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1969001ybi; Sat, 13 Jul 2019 04:11:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9PO3Lu+1XWUFJg1amQUCaatkcq8OS4FCsXDHIMAH7pAd60lWGhfw7ZEz9G8g8VKdiaBAu X-Received: by 2002:a63:4104:: with SMTP id o4mr16856170pga.345.1563016262501; Sat, 13 Jul 2019 04:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563016262; cv=none; d=google.com; s=arc-20160816; b=IiqAK79lvFAYm0lNfnaGsFljveYRmoVWRaMuGa3oG5mNWPr/3+PFYikob9r3b5uZQ/ 2xShazo+rhqrzC4Dy3zFTfdy04L1NnbWAOLcDMbVq4+4i43Q17CRhzGftnG0IMPDH6Gm DtJOONRvbfevKxgHnl6PmJnallNOlgm92v5noaLYUVptuRS18rktLlYsNTgrjAWOrxmQ G3m22LR9/Zoz0/Z5Du4FXFvNVpSwnvN3xAgBaqLwmwVLpx44+8/vXiun7mEwz8qPbRUu 8nVDOfuFHmDZ8qIXY0bkMQ6mdlt/LqQUTg5oyUTZ20kohhlO2VmZ3bIhg+A+Ez/1/ohT AONg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=vguI2+ZzMuiT2lnZgJovZs4ew2EyEBVJFzPRcLpeRZ0=; b=xvDx+Lj6MH20opF0m5w2UURsMgXnPNltEIMLIAdnydv8IygbNa3+1F5sqQHOkM+OqV IAeDgP5O7jff7PNjMSf4Nu6wAx5Jil0D3uHFdxu/O8oxu2WdqR0f/zNNubefNrnEsN93 lRCtEaFaZpA785sKw8smseViZ1xaphwMq994F2DoYrtwPCtt1dgPpa7WVcCL7a8Yn+XZ izmN3WenubvZ4cw1YHHwJt15ePBgGfyJTEtol/4nHx23RcF0Kg3OMV7+gfUC7dYBruou r8tJSxhIVQfo5WFP3mwmDRYjLg6RThtcWZhv5Vgx/xy1Zbsb7+raOGKr/UMcKwFPijQ6 HcSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b=YKttcKeF; 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=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f59si10240025plb.107.2019.07.13.04.10.46; Sat, 13 Jul 2019 04:11:02 -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=@zytor.com header.s=2019061801 header.b=YKttcKeF; 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=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727854AbfGMLJj (ORCPT + 99 others); Sat, 13 Jul 2019 07:09:39 -0400 Received: from terminus.zytor.com ([198.137.202.136]:35563 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbfGMLJj (ORCPT ); Sat, 13 Jul 2019 07:09:39 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x6DB9R7C3841578 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 13 Jul 2019 04:09:27 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x6DB9R7C3841578 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1563016168; bh=vguI2+ZzMuiT2lnZgJovZs4ew2EyEBVJFzPRcLpeRZ0=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=YKttcKeF3qUUAUrdtGwOgg42+qhSKL5z/zlYdCBKYvNTc0aHA68muCV9oF+WwGp/j +v9u9rw7VtNGRWSfM4tkFi37JsQrIdx5Li9fCEOaQv8Ult55xr5mwAsgbccqhSwJlQ tIb52zSS8brvTGgHzGy3GH64erQkvrdUBoZxJxoo3q67qqi5ThJht2uihlvSASbrnF Mgpm9PDLNstdK96ReEhGD7WYj1Iuus+aBoDY7RqlP45OBfZbUjb90pHsyu2AjdICbc mepUuf+75MZY/7XHtm7PerSvwEy0d6pKqJZMeFiJrH8LhGP/Nsik7S5vaN38ya7kdi YZqPKA+ubyAGQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x6DB9QNJ3841575; Sat, 13 Jul 2019 04:09:26 -0700 Date: Sat, 13 Jul 2019 04:09:26 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Leo Yan Message-ID: Cc: jolsa@redhat.com, suzuki.poulose@arm.com, namhyung@kernel.org, leo.yan@linaro.org, hpa@zytor.com, tglx@linutronix.de, mathieu.poirier@linaro.org, mingo@kernel.org, acme@redhat.com, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Reply-To: adrian.hunter@intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org, acme@redhat.com, alexander.shishkin@linux.intel.com, mathieu.poirier@linaro.org, mingo@kernel.org, leo.yan@linaro.org, hpa@zytor.com, tglx@linutronix.de, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com In-Reply-To: <20190708143937.7722-4-leo.yan@linaro.org> References: <20190708143937.7722-4-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool Git-Commit-ID: 323fd749821daab0f327ec86d707c4542963cdb0 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_06_12,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, DKIM_VALID_EF autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 323fd749821daab0f327ec86d707c4542963cdb0 Gitweb: https://git.kernel.org/tip/323fd749821daab0f327ec86d707c4542963cdb0 Author: Leo Yan AuthorDate: Mon, 8 Jul 2019 22:39:36 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 9 Jul 2019 10:13:28 -0300 perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/intel-pt.c:3200 intel_pt_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 3196) tools/perf/util/intel-pt.c:3206 intel_pt_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 3200) tools/perf/util/intel-pt.c 3196 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 3197 pt->synth_opts = *session->itrace_synth_opts; 3198 } else { 3199 itrace_synth_opts__set_default(&pt->synth_opts, 3200 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3201 if (!session->itrace_synth_opts->default_no_sample && 3202 !session->itrace_synth_opts->inject) { 3203 pt->synth_opts.branches = false; 3204 pt->synth_opts.callchain = true; 3205 } 3206 if (session->itrace_synth_opts) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3207 pt->synth_opts.thread_stack = 3208 session->itrace_synth_opts->thread_stack; 3209 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_pt_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-4-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-pt.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index c76a96f777fb..df061599fef4 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3210,7 +3210,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { pt->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&pt->synth_opts, @@ -3220,8 +3220,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->synth_opts.branches = false; pt->synth_opts.callchain = true; } - if (session->itrace_synth_opts) - pt->synth_opts.thread_stack = + pt->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; } @@ -3241,11 +3240,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; } - if (session->itrace_synth_opts) { - err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); - if (err) - goto err_delete_thread; - } + err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); + if (err) + goto err_delete_thread; if (pt->synth_opts.calls) pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC |