Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1427177ybh; Mon, 13 Jul 2020 19:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlzYQ0K/dW6zxBIqUKUF8X40pdPXFiCsfseErlIJniNBvonD1jLXc8QLYTlBUS2uYYwQb0 X-Received: by 2002:aa7:da89:: with SMTP id q9mr2265750eds.273.1594694085384; Mon, 13 Jul 2020 19:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594694085; cv=none; d=google.com; s=arc-20160816; b=JL+pxkjjazz5gBP9uTUnZNm1Ki7p1J4aVbc21lw/yqsY1GVZrfdqbSy+j97jiGh1nC +sX0RZxUT5/32DensJlvbg/+pcsX1BOmPTnksYDA9RcnyiRC8ppdGAc4n5hVFEJBTsrs tMleoQYFBK7w3FBGZT4OoEAmeZBDXd/4I1KTrtOfJr94HzR0ZA6r135DvcRz/8sIqDFH 4alc/oWurwXdgsw9mUR3hp1C6HGUUPvvBdtZwFazep7DdUX67uX4S9M1n1odQzKFmd7s NHPQ3L1jPDZxZsyJbeQ9s295B9+/7eUowBCZmTELvjKct6gW1I3ZWmbu4ziYpKOYjeHf m9zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=5G68UthMCKD1aen/DRRZF4pk8HURbsRm0rU5D+pNYvs=; b=bZcvzF/xzZTG9vh66S42Ksb+dAvCd2s/b+xDjTtbW5kmd6bgtIso1iO2jId3BZMF54 SioqtpzGHKrlZ4Bg3jw2sil14/XVvopkjKNYHtEtTI3eFIh6WqyE4hobn0gxIhm8wIw4 I260cXVgUKtHTYOVGMwE3FdEwbhu51e+OOmc03w4UQabsFlZlhBahoQAwdLXpYx+Wrvp b4M5jipK+jeasik6bhTIUD6XpIKHswe7nMsejpZKo8PQCYHDy7T0Wkgq2E2wl+zWDA1b 6yKKerLtpteBWU9ozt9Azqy7n+Mq3YOktNYmvp7AUlt5TJ94Dt2oJHwrXx0K/nd+Jm9F WMAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si10993752ejv.383.2020.07.13.19.34.22; Mon, 13 Jul 2020 19:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbgGNCdp (ORCPT + 99 others); Mon, 13 Jul 2020 22:33:45 -0400 Received: from smtp23.cstnet.cn ([159.226.251.23]:42736 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726150AbgGNCdp (ORCPT ); Mon, 13 Jul 2020 22:33:45 -0400 Received: from localhost (unknown [159.226.5.99]) by APP-03 (Coremail) with SMTP id rQCowAC3vwMJFw1fLmaPAA--.28728S2; Tue, 14 Jul 2020 10:23:06 +0800 (CST) From: Xu Wang To: davem@davemloft.net, kuba@kernel.org, michal.simek@xilinx.com, esben@geanix.com, hkallweit1@gmail.com, f.fainelli@gmail.com, vulab@iscas.ac.cn, weiyongjun1@huawei.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] net: xilinx: fix potential NULL dereference in temac_probe() Date: Tue, 14 Jul 2020 02:23:04 +0000 Message-Id: <20200714022304.4003-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: rQCowAC3vwMJFw1fLmaPAA--.28728S2 X-Coremail-Antispam: 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226.5.99] X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiCAsQA18J9fBAqAABsq Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org platform_get_resource() may return NULL, add proper check to avoid potential NULL dereferencing. Signed-off-by: Xu Wang --- drivers/net/ethernet/xilinx/ll_temac_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c index 929244064abd..85a767fa2ecf 100644 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -1408,6 +1408,8 @@ static int temac_probe(struct platform_device *pdev) /* map device registers */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -EINVAL; lp->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!lp->regs) { @@ -1503,6 +1505,8 @@ static int temac_probe(struct platform_device *pdev) } else if (pdata) { /* 2nd memory resource specifies DMA registers */ res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (!res) + return -EINVAL; lp->sdma_regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!lp->sdma_regs) { -- 2.17.1