Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2879896pxu; Sat, 19 Dec 2020 05:08:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGA0mYL7YBbxpCO44x9i2wTus35IeGk7VRJYOTe3Aio46EQqqeFGCmYVOnyezB+ZkvqNoa X-Received: by 2002:a17:906:e24f:: with SMTP id gq15mr8497286ejb.256.1608383332931; Sat, 19 Dec 2020 05:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608383332; cv=none; d=google.com; s=arc-20160816; b=Q8A+U3MVJtmYTZTJ36IinTELBlF2l4Hczb78KQ/OIVwcrhwf+xSICkcamkaEQTJ5K3 OnqbNIq08fEJUQRdgyG1imJ2YNfuWekg3tKK3m+Xw8WriYTQ1AfooqDf3aY77W1+nS41 H2g2YNnWSykEJpkkBFWnXuSl8sltGDoJ5hFUNJ+EClgcA5I5Vdx96nyxSkg3tRZa+2nC 5okHzzmNH9fYAqHBYQqoafmcYXz1EUjs7B+3zA9OwKjklwczWKeOV4zMgtUVikUCVzGX 8ClflFR8ZkUM3hI2Uk9Ntg738MwqVRn5/Pn7TIChuIJtfpiwbjZUqx7aYqh+q6lbefCS no4w== 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=iG2ESgHmg3SisGqwEKdgt2Ql9III2vCuBByuOJD7N5w=; b=c5/QBvcRWK3sq1OIN95TRanoMzFvNdf3VhxWsvK/L8xVCQ66L+d2+E02jGed/7eiRO Kb3AZt9CbB82isFysvYiMp4uxFOjQCuZYKaOf2HDe78n64GIZP6MMx0bAEmxjlPJdqV5 BRssELpD7IUSJ41464TmkYgtsfqTCCtxhwEQrNUsAY6PH/rRrykcYHLwAPfIiUVKxakr wqMq3XQKiAHHMD6A7TbYvCApnlWrDs+2E9ygGA+ydzc6kljXy4vV2vJ/FJq06/lRJnb+ 6QvGFO7ihL0MTVlxjDkULYsBoKCkL7KD6FHnmIU866tmIgkMvK6j/I39WHpQP82YiAR6 Nl5w== 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 dk7si7178594ejb.687.2020.12.19.05.08.30; Sat, 19 Dec 2020 05:08:52 -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 S1727826AbgLSNGt (ORCPT + 99 others); Sat, 19 Dec 2020 08:06:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:51312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbgLSNDn (ORCPT ); Sat, 19 Dec 2020 08:03:43 -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.4 16/34] net: ll_temac: Fix potential NULL dereference in temac_probe() Date: Sat, 19 Dec 2020 14:03:13 +0100 Message-Id: <20201219125342.181724337@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125341.384025953@linuxfoundation.org> References: <20201219125341.384025953@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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -1425,9 +1425,7 @@ 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_nocache(&pdev->dev, res->start, - resource_size(res)); + 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");