From patchwork Tue Jul 2 10:34:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168305 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072669ilk; Tue, 2 Jul 2019 03:35:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwP/b9vSif7FCnPRxlhawTOtCp5zSH/ktFvC/FVIf7C1auqGGdp86mKEvrKZm9MCxjKStdp X-Received: by 2002:a17:90a:f498:: with SMTP id bx24mr4856613pjb.91.1562063744913; Tue, 02 Jul 2019 03:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063744; cv=none; d=google.com; s=arc-20160816; b=W0soyBWENXHad3MaO7z8KKRynmdJK0FRD+ZiP5+0dKnGXWiqxAXRPSWUxHCcKOT5gF sUOxs3HS2qSZC+nAo4FHxyxXxKsXrHjP470yEtu3uid0eLsGMd3+BPJYXACEOMC0miyU 4b9wGdO9MLDzI9WI/WgV4J09mpHzd9Qlx4NY5EAVXLIzHvzj0h6S8/x5O2GUzZ0n/wPa KRhDA34iPcsf/5xuAvs5eYyjAMcgA5rW3XnEthk1yIWSPVtJChofFbKLsDh5MHPQ94aG R5gc7mrZFvVxNqFxeLDI6waYeqZXLvfTVr/G9uhVmXFZCQLulqFZXJgQNPJVAmUmjbyq wttA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=YSndylDxzYonF2kLsuYH4mlKiK+ftpV0QJO1Ajv5nE4y2ve9wa45q+5zPDTo6474hQ qkoGFvu/uEMsMjX8i+poSwscgyOBJIPIUh550rpL++WKNaBi8Rnt1KW5c1ocWqKVJqGn 7CmlBRU5LlJEI0eLArOhK+FSnWi1wjsHqFAEMjbzaJOjXzN2Q4mqpyE93R3qU/tuKOjQ PN+0W7lS+Ry/nSzGrzLUCMUSw3+Tv0+/2uUhAPrT1El0SNglP1bprkUILGp8fVXphPQy Ve82/LffU0HmALAYJ9ZpL5Iro+oDd5t2M7QHfGpb//7oS6J6NQC9ojR/ooyAJpTKFuC4 eaig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qjjisz9+; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si12421035pll.214.2019.07.02.03.35.44; Tue, 02 Jul 2019 03:35:44 -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=@linaro.org header.s=google header.b=Qjjisz9+; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbfGBKf1 (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:27 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:39409 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKf0 (ORCPT ); Tue, 2 Jul 2019 06:35:26 -0400 Received: by mail-oi1-f196.google.com with SMTP id m202so12622160oig.6 for ; Tue, 02 Jul 2019 03:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=Qjjisz9+e7yYwO6xLzJxQ9HbSJNib4eLc/3vLq48/xqqic/aAX4AvVAU/q5Zop1wmJ XkmTke4IVTLDngJtze/ZkDjaA1QU2R2D/kHisk1UxjpNfhZtzV+/+629pPbm+Ug4uQB3 4FUiB7Cc9UYcJjXd+1RdHn98NgTgP+CyF3zfcn8HHtP4zbskHeNvhiTO+SBYh8XED2gK tgRH9S+HRPx4neVupbgOI+Jf8yoEA/nT9Hu9YsNGYeST0SZxaf7/1ytrlD2AQQgeCoI8 QHpmQwLSW44gvSGD2fR7zcUfA5vt3FIfsqKNmFUkJO+2QCNdtXC1KzICntwRsWO7lm+s l/Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=ZhWtOEMWNsZTy66YnUSfM+vSeMkQXQjREusRvBKXrlKSlM7PydkH7stkzRWGpHjlu6 +7g15x+rVWqM9g2NTLSmhkb4CCf4loZuaoTgionVeck7M/udDy2d+kLYpl1DyxW5zitj UXu1kk3ZyfZYm0bqQS3WqXiuGsVJDYPY3rDbWo1AHn5dLa8cVrmvWrwAER7lVEg8IbW5 ZY5C2pwQ/12IgsXwczUmnPErCeckrehAWew+Q6ssMGA+EOFyOBABGsRozwf13er4CQ7v 3su9rsdqFLSZwngaZgU8unFEN0dJCjMJcZ1b26WOxXRT2OUM7ug81+RV0gAWm3rmMT/1 uQuw== X-Gm-Message-State: APjAAAW+W/IL6PLOMra5UOi3pBe66ryje61/6yJPjlMFjp5bxpz3xVrp m9YUWwaYwUOFkiuIkqh6zXoiKg== X-Received: by 2002:a54:4615:: with SMTP id p21mr2435033oip.22.1562063726111; Tue, 02 Jul 2019 03:35:26 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 61sm5139805otx.8.2019.07.02.03.35.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:25 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Andi Kleen , "David S. Miller" , Davidlohr Bueso , Rasmus Villemoes , Jin Yao , Song Liu , Adrian Hunter , Alexios Zavras , Thomas Gleixner , Changbin Du , Eric Saint-Etienne , Konstantin Khlebnikov , Thomas Richter , Alexey Budankov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v1 05/11] perf trace: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:14 +0800 Message-Id: <20190702103420.27540-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702103420.27540-1-leo.yan@linaro.org> References: <20190702103420.27540-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/builtin-trace.c:1044 thread_trace__new() error: we previously assumed 'ttrace' could be null (see line 1041). tools/perf/builtin-trace.c 1037 static struct thread_trace *thread_trace__new(void) 1038 { 1039 struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); 1040 1041 if (ttrace) 1042 ttrace->files.max = -1; 1043 1044 ttrace->syscall_stats = intlist__new(NULL); ^^^^^^^^ 1045 1046 return ttrace; 1047 } This patch directly returns NULL when fail to allocate memory for ttrace; this can avoid potential NULL pointer dereference. Signed-off-by: Leo Yan --- tools/perf/builtin-trace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index f3532b081b31..874d78890c60 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1038,9 +1038,10 @@ static struct thread_trace *thread_trace__new(void) { struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); - if (ttrace) - ttrace->files.max = -1; + if (ttrace == NULL) + return NULL; + ttrace->files.max = -1; ttrace->syscall_stats = intlist__new(NULL); return ttrace;