From patchwork Thu Jan 18 14:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 10173267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E621603B5 for ; Thu, 18 Jan 2018 13:54:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C80E269A3 for ; Thu, 18 Jan 2018 13:54:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80F1D28210; Thu, 18 Jan 2018 13:54:28 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BFF5269A3 for ; Thu, 18 Jan 2018 13:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756367AbeARNyZ (ORCPT ); Thu, 18 Jan 2018 08:54:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:4665 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756363AbeARNyY (ORCPT ); Thu, 18 Jan 2018 08:54:24 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9D426B7A8388A; Thu, 18 Jan 2018 21:54:08 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Thu, 18 Jan 2018 21:54:04 +0800 From: Wei Yongjun To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas CC: Wei Yongjun , , , Subject: [PATCH -next] PCI: dra7xx: Fix potential NULL dereference Date: Thu, 18 Jan 2018 14:00:37 +0000 Message-ID: <1516284037-81537-1-git-send-email-weiyongjun1@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP platform_get_resource_byname() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code. This is detected by Coccinelle semantic patch. @@ expression pdev, res, n, t, e, e1, e2; @@ res = platform_get_resource_byname(pdev, t, n); + if (!res) + return -EINVAL; ... when != res == NULL e = devm_ioremap(e1, res->start, e2); Fixes: 608793e27b33 ("PCI: dwc: dra7xx: Add EP mode support") Signed-off-by: Wei Yongjun --- drivers/pci/dwc/pci-dra7xx.c | 6 ++++++ 1 file changed, 6 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c index 8bf7c27..aafded8 100644 --- a/drivers/pci/dwc/pci-dra7xx.c +++ b/drivers/pci/dwc/pci-dra7xx.c @@ -409,11 +409,15 @@ static int __init dra7xx_add_pcie_ep(struct dra7xx_pcie *dra7xx, ep->ops = &pcie_ep_ops; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics"); + if (!res) + return -EINVAL; pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res)); if (!pci->dbi_base) return -ENOMEM; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics2"); + if (!res) + return -EINVAL; pci->dbi_base2 = devm_ioremap(dev, res->start, resource_size(res)); if (!pci->dbi_base2) return -ENOMEM; @@ -462,6 +466,8 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx, return ret; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbics"); + if (!res) + return -EINVAL; pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res)); if (!pci->dbi_base) return -ENOMEM;