Skip to contentSkip to conversation

net: qcom/emac: fix return value check in emac_sgmii_config()

PATCH Applied Wei Yongjun 3 participants 3 messages Oct 1, 2016 – Oct 4, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: qcom/emac: fix return value check in emac_sgmii_config()

From: Wei Yongjun <[email protected]>

In case of error, the function ioremap() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Also add check for return value of platform_get_resource().

Fixes 54e19bc74f33 ("net: qcom/emac: do not use devm on internal

phy pdev")

---
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/qualcomm/emac/emac-sgmii.c +9 -4
index 3d2c05a..75c1b53 100644
@@ -740,9 +740,14 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt)
 
 	/* Base address is the first address */
 	res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		ret = -EINVAL;
+		goto error_put_device;
+	}
+
 	phy->base = ioremap(res->start, resource_size(res));
-	if (IS_ERR(phy->base)) {
-		ret = PTR_ERR(phy->base);
+	if (!phy->base) {
+		ret = -ENOMEM;
 		goto error_put_device;
 	}
 
@@ -750,8 +755,8 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt)
 	res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 1);
 	if (res) {
 		phy->digital = ioremap(res->start, resource_size(res));
-		if (IS_ERR(phy->digital)) {
-			ret = PTR_ERR(phy->digital);
+		if (!phy->digital) {
+			ret = -ENOMEM;
 			goto error_unmap_base;
 		}
 	}
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Wei Yongjun

From: Wei Yongjun<[email protected]>

In case of error, the function ioremap() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Also add check for return value of platform_get_resource().

Fixes 54e19bc74f33 ("net: qcom/emac: do not use devm on internal

phy pdev")

Thanks for this. When I switched from devm_ioremap_resource() to ioremap(), I didn't think to verify the return values.

Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
maintainer Applied
#2 lore raw
In reply to Wei Yongjun

From: Wei Yongjun <[email protected]>
Date: Sat, 1 Oct 2016 09:12:29 +0000

Quoted 11 lines

From: Wei Yongjun <[email protected]>

In case of error, the function ioremap() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Also add check for return value of platform_get_resource().

Fixes 54e19bc74f33 ("net: qcom/emac: do not use devm on internal

phy pdev")

Applied, thanks.