Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2880076pxu; Sat, 19 Dec 2020 05:09:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCISHFJBLo4Y2V6vOfxV1qzVvt42re6FiXrG7yjFiLpr1GXmoZjhz/4GznBG86zpqU49Rb X-Received: by 2002:a50:c3c5:: with SMTP id i5mr8731537edf.166.1608383351970; Sat, 19 Dec 2020 05:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608383351; cv=none; d=google.com; s=arc-20160816; b=RY1ew/QNspwFsjJ64rbtJfBHnGN167h+Cgh83I1ha2qdHI3LuzUaItg1Ia5zYylttU NoCYAjGIlKCvMmQpsPjW01MRMAaZhCZXy1qW5q/rv2eoVGZtlCe70q5URGyd6Zs90H7t Ptumxdo3WvHfscgZ2AXkQ1I097yT9stRtO1RQtQWFjFmBgQVUaWqL1xNnIuqhO7YveTJ EbGqeo6+osznauROlJcJQX8iMlN5885AM5zMUPPDPNfrNIYCNYyA1nOmjemojRasvFOH mnXUhC4FEeLntdr+G8xkL5xlVU8Qmuz1LkXyV6j5nDkbZvUiWg85WjhCkAWv2D0t7eYv 39OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=2u/46ldzykTTiwF5EHMhFzSaHDMa0hm674gmfpiER5U=; b=r3RwF2WM6BmtvUNFQeWrFISxAtmX9VuELQPhi4r5LRownJ2T2KXfhZXvYHv+fsSGD3 SWpgBvyfr/JfzKQoL4X3YRekjLcPQBXersb2QNXQ999volHj0uukfP4LodxT4fvuNliz 9GGVteaL4R1YpEsWx9zndiqXiZYlMkgh2hael6bnmvhtB5jtgSqXYOpdtxsxFJzqOapH CQ6vTARvwoT+qQAH947nAN4Hg/ErDR5/2PCGRAFu1HWUAK54e4Ir223rOsGtMdgBu5qw 99+ZL6jlppGv79jwx8grTaE3KlIRejt/QyG9u/nRCYiKsU5VH+oEgyERJt22vYK0yBkD M44w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si7777102edx.538.2020.12.19.05.08.49; Sat, 19 Dec 2020 05:09:11 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728098AbgLSNHG (ORCPT + 99 others); Sat, 19 Dec 2020 08:07:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:45356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727779AbgLSM6l (ORCPT ); Sat, 19 Dec 2020 07:58:41 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Changzhong , Esben Haabendal , "David S. Miller" Subject: [PATCH 5.9 19/49] net: ll_temac: Fix potential NULL dereference in temac_probe() Date: Sat, 19 Dec 2020 13:58:23 +0100 Message-Id: <20201219125345.623282459@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125344.671832095@linuxfoundation.org> References: <20201219125344.671832095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Changzhong [ Upstream commit cc6596fc7295e9dcd78156ed42f9f8e1221f7530 ] platform_get_resource() may fail and in this case a NULL dereference will occur. Fix it to use devm_platform_ioremap_resource() instead of calling platform_get_resource() and devm_ioremap(). This is detected by Coccinelle semantic patch. @@ expression pdev, res, n, t, e, e1, e2; @@ res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n); + if (!res) + return -EINVAL; ... when != res == NULL e = devm_ioremap(e1, res->start, e2); Fixes: 8425c41d1ef7 ("net: ll_temac: Extend support to non-device-tree platforms") Signed-off-by: Zhang Changzhong Acked-by: Esben Haabendal Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/xilinx/ll_temac_main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -1351,7 +1351,6 @@ static int temac_probe(struct platform_d struct device_node *temac_np = dev_of_node(&pdev->dev), *dma_np; struct temac_local *lp; struct net_device *ndev; - struct resource *res; const void *addr; __be32 *p; bool little_endian; @@ -1500,13 +1499,11 @@ static int temac_probe(struct platform_d of_node_put(dma_np); } else if (pdata) { /* 2nd memory resource specifies DMA registers */ - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); - lp->sdma_regs = devm_ioremap(&pdev->dev, res->start, - resource_size(res)); - if (!lp->sdma_regs) { + lp->sdma_regs = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(lp->sdma_regs)) { dev_err(&pdev->dev, "could not map DMA registers\n"); - return -ENOMEM; + return PTR_ERR(lp->sdma_regs); } if (pdata->dma_little_endian) { lp->dma_in = temac_dma_in32_le;