Skip to contentSkip to conversation

net: moxa: Use devm_platform_get_and_ioremap_resource()

PATCH In review Yang Yingliang 2 participants 2 messages Jul 16, 2021 – Jul 19, 2021 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: moxa: Use devm_platform_get_and_ioremap_resource()

[ Upstream commit 35cba15a504bf4f585bb9d78f47b22b28a1a06b2 ]

Use devm_platform_get_and_ioremap_resource() to simplify code and avoid a null-ptr-deref by checking 'res' in it.

[yyl: since devm_platform_get_and_ioremap_resource() is introduced
in linux-5.7, so just check the return value after calling platform_get_resource()]

---
 drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/moxa/moxart_ether.c +4 -0
index f70bb81e1ed65..caf7051302725 100644
@@ -481,6 +481,10 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	priv->pdev = pdev;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		ret = -EINVAL;
+		goto init_fail;
+	}
 	ndev->base_addr = res->start;
 	priv->base = devm_ioremap_resource(p_dev, res);
 	if (IS_ERR(priv->base)) {
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 9 lines · Yang Yingliang

[ Upstream commit 35cba15a504bf4f585bb9d78f47b22b28a1a06b2 ]

Use devm_platform_get_and_ioremap_resource() to simplify code and avoid a null-ptr-deref by checking 'res' in it.

[yyl: since devm_platform_get_and_ioremap_resource() is introduced
in linux-5.7, so just check the return value after calling platform_get_resource()]

Quoted 5 lines
---
 drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
 1 file changed, 4 insertions(+)

Now queued up, thanks.

greg k-h