Skip to contentSkip to conversation

phy: hix5hd2-sata: Check return value of platform_get_resource

PATCH In review Axel Lin 2 participants 2 messages Mar 2, 2015 Generic PHY framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 phy: hix5hd2-sata: Check return value of platform_get_resource

This prevent NULL pointer dereference if res is NULL.

---
This patch replaces [PATCH] phy: hix5hd2-sata: Convert to use devm_ioremap_resource, as zhangfei pinted out that the memory region is shared with sata controller so devm_request_mem_region would fail.

 drivers/phy/phy-hix5hd2-sata.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/phy/phy-hix5hd2-sata.c +3 -0
index 34915b4..d6b2265 100644
@@ -147,6 +147,9 @@ static int hix5hd2_sata_phy_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	priv->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!priv->base)
 		return -ENOMEM;
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Axel Lin

This prevent NULL pointer dereference if res is NULL.

Thanks

Quoted 22 lines

---
This patch replaces [PATCH] phy: hix5hd2-sata: Convert to use devm_ioremap_resource, as zhangfei pinted out that the memory region is shared with sata controller so devm_request_mem_region would fail.

  drivers/phy/phy-hix5hd2-sata.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/phy/phy-hix5hd2-sata.c +3 -0
index 34915b4..d6b2265 100644
@@ -147,6 +147,9 @@ static int hix5hd2_sata_phy_probe(struct platform_device *pdev)
  		return -ENOMEM;
 
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
  	priv->base = devm_ioremap(dev, res->start, resource_size(res));
  	if (!priv->base)
  		return -ENOMEM;