From patchwork Fri Jun 21 17:52:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11010465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1099924 for ; Fri, 21 Jun 2019 17:52:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92C6528720 for ; Fri, 21 Jun 2019 17:52:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8709E28B89; Fri, 21 Jun 2019 17:52:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 256E028B8B for ; Fri, 21 Jun 2019 17:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4TFkK9QcVxFd3XuH9JarhYL+Hm2tRHyR8eF6s1kPa+k=; b=TyjUIvk1tcSOBDJ0blmhL7eMTd rLkUPK+8s7IIGzdJP9qTNZhAjF/4pjt4W3UgMIjZJZ6Zno3oKB0xhOn28ZPFpfFjvgpu93DBoBOZC zV66u4XlP+Nfhr8gpx/p57W/6GdwtgtodUCcCD1VkSKmW7qWQh9XAdcSMEYR/e/te6g6knq1UgAzm +7euxDMLrT/eK0qGG+a1UvrGjfs3ud3/yACRbKFVJIi3o6FQ+ujWRD69uOVUJcoanKDA5lQS1uRTJ NghwYy9m8f3eAA2P0L9/qx6T+uuANEWQppYcY/DMCB6fLsru70OSAfvigs+KoRJmQTL1OCKTNV3e2 Che981CQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1heNi7-0000ZM-EX; Fri, 21 Jun 2019 17:52:27 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1heNho-0000LO-3x for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2019 17:52:09 +0000 Received: by mail-pf1-x443.google.com with SMTP id t16so3962690pfe.11 for ; Fri, 21 Jun 2019 10:52:08 -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=ZB/QEA/K3clWkDbM4qhRU5KEkoHlA3Iglne8yOGj5AU=; b=iTIUWqsoU12Tvqa0aExnW7y3oEJw/5vcH4D7VO9h8yiEl9TujJtWLfTfg9skwgS67B yBnitIFNIbHLhW9ZnapxeQ0Agrv4836sWZ7ewk2KXg169IKqnRzZVwzYYhVZb2qbGOnL BytT2IWR/dizPmCFINJY5SYRoeyPzPnkjhU7/YT/QKsqHxCRQQun4+RRZWDbUwF3YjM9 MNR6Z+T/APlg+D+/+ucFrpUeGitPlvQXgZb46R5vhOpbVFeICXtS9720YaBkWLdQrr7L HcfJl6tGg3mDv1HquHx7Ftp3mikeu3yawPypb5E5oGNVkw6J3bIrPldjBzlHN2budhT/ jBTw== 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=ZB/QEA/K3clWkDbM4qhRU5KEkoHlA3Iglne8yOGj5AU=; b=ZtW5ukrpjjkwnJDnhX0LDFyKYTf5J+aCY4Oep8lNtHsR/MWkZyN9HX6JXnJ96P6auV Cqi8JLvJTud47ozNe6IOOej2xY4kEwfP2nomCvochcCrjQ8gRG8v7+S8Fosw/iBKuWAM zVZ49hgXjTge/vvX32h6kFlYThllk2bq5gamzieodMZvlfius2BtmpCOlb7aMmQExdpW plyfCI9yvSUtBSX8bwz5oAgYOs3hLbCR06zO0MlouVn0XbVlvDky59s9FdDDy5GfgYfS BcIw4oVHcjDbQUCDt50/1R/C2hKKdenMW8x3x+QCTnu/UloHukrzaspUvB6qHgvqJUhZ Aj/Q== X-Gm-Message-State: APjAAAXXXP6HZXL00ecqLPLBRRbZkyIpw5RBzUEms5Fht6S2YzymTdB6 9Vqv0gLiD5XmZgmpifWk4pyQxG6O0nNWDw== X-Google-Smtp-Source: APXvYqyJyBZ39uTFFbC//U31ABdP2wCeU+mwtjx2+PPLr3K0iv4dpPUFsBFj3tl2WCAnnEfWFwqIzw== X-Received: by 2002:a63:5152:: with SMTP id r18mr19645487pgl.324.1561139527640; Fri, 21 Jun 2019 10:52:07 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id f17sm3378490pgv.16.2019.06.21.10.52.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 10:52:07 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Subject: [PATCH 1/2] coresight: etm3x: Smatch: Fix potential NULL pointer dereference Date: Fri, 21 Jun 2019 11:52:04 -0600 Message-Id: <20190621175205.24551-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190621175205.24551-1-mathieu.poirier@linaro.org> References: <20190621175205.24551-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190621_105208_168396_6FFD6833 X-CRM114-Status: GOOD ( 12.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Suzuki K Poulose Based on the following report from Smatch tool, make sure we have a valid drvdata before we dereference it to find the real dev. The patch 21d26b905c05: "coresight: etm: Clean up device specific data" from May 22, 2019, leads to the following Smatch complaint: ./drivers/hwtracing/coresight/coresight-etm3x.c:460 etm_get_trace_id() warn: variable dereferenced before check 'drvdata' (see line 458) ./drivers/hwtracing/coresight/coresight-etm3x.c 457 int trace_id = -1; 458 struct device *etm_dev = drvdata->csdev->dev.parent; ^^^^^^^^^ New dereference 459 460 if (!drvdata) ^^^^^^^^ Checked too late. Delete the check? 461 goto out; 462 Cc: Mathieu Poirier Cc: Dan Carpenter Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm3x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c index bed729140718..225c2982e4fe 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x.c +++ b/drivers/hwtracing/coresight/coresight-etm3x.c @@ -455,11 +455,12 @@ int etm_get_trace_id(struct etm_drvdata *drvdata) { unsigned long flags; int trace_id = -1; - struct device *etm_dev = drvdata->csdev->dev.parent; + struct device *etm_dev; if (!drvdata) goto out; + etm_dev = drvdata->csdev->dev.parent; if (!local_read(&drvdata->mode)) return drvdata->traceid; From patchwork Fri Jun 21 17:52:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11010467 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABCA813AF for ; Fri, 21 Jun 2019 17:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E71C28B87 for ; Fri, 21 Jun 2019 17:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92D5728B8D; Fri, 21 Jun 2019 17:52:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B27A28B87 for ; Fri, 21 Jun 2019 17:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=D9jRnard3J+PoJaR3OiZxbqJH4eRH7tuLcvTRY0EKZw=; b=TwkbkmbSXLVwzm4tPk/sWJSKAn O7RhY2WLlbgWbXrw4mJItDIlOCYD2MlZNqOZsNoErLyVCcujSv5pY2QGm0E17PMnW8iAfugTQ062+ rklTZNIY/x6wysijPXtIqtdDVMaOcHp0gONMvNQCnnDGIIAKzUJRVd98RAqTzRDtxgUOlOzBh5oty IhYOYhKUqcxoewZKAGVvk/lbSpRytlbjEDHf5l8yvXmjaCNHsKBW7P3X4PClhOnCpovnOaHKLcxOb 2UB2BPy+7CrlYPeL8jQIbJzi5NbRdt2oVZh5Uz/v/1nec2bxxaHpHabVfj6keZwmUn25C+wPZzEKl 9jmiUxXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1heNiN-0000s2-MC; Fri, 21 Jun 2019 17:52:43 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1heNhp-0000M0-0u for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2019 17:52:10 +0000 Received: by mail-pl1-x642.google.com with SMTP id m7so3345234pls.8 for ; Fri, 21 Jun 2019 10:52:08 -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=2hwzeXx3N76bGEMIhEEJzpn1YisLcq/x9TD1i9ttN0s=; b=Id3/SHMeDhTT9yWO1Pqsj8bgUsa8y5DR/CWLU3QVECdPoeHad1a6G0bCCzd3zVtDkb DDz4LJ/3kkpLEQZAIdZrdKaQDy6TQ3kzEPkJvUJr9lHzlhCXpC4JvCxUwGCxN2JiOkPp W+41NbCOLicVKogCaZPUvkf0c/noaHm9DSdthwmYmd5xBqo8JA4lcSUUL9J46me51ELB aMBIJdMQg2jZoch0my/eBfuCl7mYV3/TWsTFf/W+2vYINy3sdKQdjfxDjGJ8EyItTiZf GhalobD4qJ2iGVVPQnNDBN+600grfckFq+kdPo7XLFnxhymhBNa8ucbhmbeBAOi1U2Gj Mztg== 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=2hwzeXx3N76bGEMIhEEJzpn1YisLcq/x9TD1i9ttN0s=; b=Ux3D5lt13fcT8gXtf33MqfJr020iTnthYNyR1MXR8NRQYgIpvcaKeV4Us3etu+LcSz qaG+Ph4LIlgqI6L4JdGYvIzEwRvgx4LHq8geuW5M9ftJOG9STnUwRYyZ2ugKgSKjVTwx u3Lq9t75uPo+0OPFolbvSdB93U/LJQccefgbXIEBsls4OPyRBAyhzSBbJXIMXdIY+vk6 aNDXtIK30dkP25tzlvSrNkbEaSDFz6RTDPbhSa+HIp6hJ+Ma4TdL9myoi2PC7RTnm0u1 IabDlSOVWy4AtsjzbVmyqzb1zEb42dnL+z2J8yyRKZWV7U2v+Ve/H7Yrcgb3J4Ltq7a2 2FPA== X-Gm-Message-State: APjAAAWRjpTJKa0JH7z/ZrakuCEL1AyvwQpQJLVqusyzZhngzZCNqWIU KnF9I/AlsGJo8e+g7HAW6D+EzxRBdQyrEA== X-Google-Smtp-Source: APXvYqyb0E3MNntkLQyCKmKCtwJJJvk8z+sk5wZp2mXFvUVDcnSOHr8d5G1Ik580PTiBmcxelzy09w== X-Received: by 2002:a17:902:9a82:: with SMTP id w2mr114236213plp.291.1561139528449; Fri, 21 Jun 2019 10:52:08 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id f17sm3378490pgv.16.2019.06.21.10.52.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 10:52:08 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Subject: [PATCH 2/2] coresight: tmc: Smatch: Fix potential NULL pointer dereference Date: Fri, 21 Jun 2019 11:52:05 -0600 Message-Id: <20190621175205.24551-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190621175205.24551-1-mathieu.poirier@linaro.org> References: <20190621175205.24551-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190621_105209_069001_7E500474 X-CRM114-Status: GOOD ( 12.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Suzuki K Poulose Based on the following report from Smatch, fix the potential NULL pointer dereference check. The patch 743256e214e8: "coresight: tmc: Clean up device specific data" from May 22, 2019, leads to the following Smatch complaint: drivers/hwtracing/coresight/coresight-tmc-etr.c:625 tmc_etr_free_flat_buf() warn: variable dereferenced before check 'flat_buf' (see line 623) drivers/hwtracing/coresight/coresight-tmc-etr.c 622 struct etr_flat_buf *flat_buf = etr_buf->private; 623 struct device *real_dev = flat_buf->dev->parent; ^^^^^^^^^^ The patch introduces a new NULL check 624 625 if (flat_buf && flat_buf->daddr) ^^^^^^^^ but the existing code assumed it can be NULL. 626 dma_free_coherent(real_dev, flat_buf->size, 627 flat_buf->vaddr, flat_buf->daddr); Cc: Dan Carpenter Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index ce0114a5435c..a9c797c2f926 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -620,11 +620,13 @@ static int tmc_etr_alloc_flat_buf(struct tmc_drvdata *drvdata, static void tmc_etr_free_flat_buf(struct etr_buf *etr_buf) { struct etr_flat_buf *flat_buf = etr_buf->private; - struct device *real_dev = flat_buf->dev->parent; - if (flat_buf && flat_buf->daddr) + if (flat_buf && flat_buf->daddr) { + struct device *real_dev = flat_buf->dev->parent; + dma_free_coherent(real_dev, flat_buf->size, flat_buf->vaddr, flat_buf->daddr); + } kfree(flat_buf); }