Skip to contentSkip to conversation

phy: ti: gmii-sel: check of_get_address() for failure

PATCH Applied Dan Carpenter 3 participants 3 messages Sep 14, 2021 – Oct 20, 2021

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

PATCH 1/1 phy: ti: gmii-sel: check of_get_address() for failure

Smatch complains that if of_get_address() returns NULL, then "size" isn't initialized. Also it would lead to an Oops.

Fixes 7f78322cdd67 ("phy: ti: gmii-sel: retrieve ports number and base offset from dt")
---
 drivers/phy/ti/phy-gmii-sel.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/phy/ti/phy-gmii-sel.c +2 -0
index 5fd2e8a08bfc..d0ab69750c6b 100644
@@ -320,6 +320,8 @@ static int phy_gmii_sel_init_ports(struct phy_gmii_sel_priv *priv)
 		u64 size;
 
 		offset = of_get_address(dev->of_node, 0, &size, NULL);
+		if (!offset)
+			return -EINVAL;
 		priv->num_ports = size / sizeof(u32);
 		if (!priv->num_ports)
 			return -EINVAL;
Signature · 7 lines
2.20.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

Smatch complains that if of_get_address() returns NULL, then "size" isn't initialized. Also it would lead to an Oops.

Fixes 7f78322cdd67 ("phy: ti: gmii-sel: retrieve ports number and base offset from dt")
---
  drivers/phy/ti/phy-gmii-sel.c | 2 ++
  1 file changed, 2 insertions(+)

Thank you.

Quoted 15 lines
drivers/phy/ti/phy-gmii-sel.c +2 -0
index 5fd2e8a08bfc..d0ab69750c6b 100644
@@ -320,6 +320,8 @@ static int phy_gmii_sel_init_ports(struct phy_gmii_sel_priv *priv)
  		u64 size;
 
  		offset = of_get_address(dev->of_node, 0, &size, NULL);
+		if (!offset)
+			return -EINVAL;
  		priv->num_ports = size / sizeof(u32);
  		if (!priv->num_ports)
  			return -EINVAL;
Signature · 7 lines
Best regards,
grygorii

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 2 lines · Dan Carpenter

Smatch complains that if of_get_address() returns NULL, then "size" isn't initialized. Also it would lead to an Oops.

Applied, thanks

Quoted 22 lines
Fixes 7f78322cdd67 ("phy: ti: gmii-sel: retrieve ports number and base offset from dt")
---
 drivers/phy/ti/phy-gmii-sel.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/phy/ti/phy-gmii-sel.c +2 -0
index 5fd2e8a08bfc..d0ab69750c6b 100644
@@ -320,6 +320,8 @@ static int phy_gmii_sel_init_ports(struct phy_gmii_sel_priv *priv)
 		u64 size;
 
 		offset = of_get_address(dev->of_node, 0, &size, NULL);
+		if (!offset)
+			return -EINVAL;
 		priv->num_ports = size / sizeof(u32);
 		if (!priv->num_ports)
 			return -EINVAL;
Signature · 1 line
2.20.1
Signature · 6 lines
~Vinod

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy