Skip to contentSkip to conversation

phy: ti: gmii-sel: Add a sanity check on the phy_id

PATCH Applied Dan Carpenter 3 participants 3 messages Oct 17, 2025 – Nov 20, 2025

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

PATCH 1/1 phy: ti: gmii-sel: Add a sanity check on the phy_id

The "phy_id" comes from the device tree so it's going to be correct. But static checkers sometimes complain when we have an upper bounds check with no lower bounds check. Also it's a bit unusual that the lowest valid number is 1 instead of 0 so adding a check could potentially help someone.

---
 drivers/phy/ti/phy-gmii-sel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/ti/phy-gmii-sel.c +1 -1
index 50adabb867cb..6cfe2538d15b 100644
@@ -341,7 +341,7 @@ static struct phy *phy_gmii_sel_of_xlate(struct device *dev,
 	if (priv->soc_data->features & BIT(PHY_GMII_SEL_RMII_IO_CLK_EN) &&
 	    args->args_count < 2)
 		return ERR_PTR(-EINVAL);
-	if (phy_id > priv->num_ports)
+	if (phy_id < 1 || phy_id > priv->num_ports)
 		return ERR_PTR(-EINVAL);
 	if (phy_id != priv->if_phys[phy_id - 1].id)
 		return ERR_PTR(-EINVAL);
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Dan Carpenter

The "phy_id" comes from the device tree so it's going to be correct. But static checkers sometimes complain when we have an upper bounds check with no lower bounds check. Also it's a bit unusual that the lowest valid number is 1 instead of 0 so adding a check could potentially help someone.

---
  drivers/phy/ti/phy-gmii-sel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/ti/phy-gmii-sel.c +0 -0
index 50adabb867cb..6cfe2538d15b 100644

drivers/phy/ti/phy-gmii-sel.c static struct phy *phy_gmii_sel_of_xlate(struct device *dev, · line 347

Quoted 8 lines
drivers/phy/ti/phy-gmii-sel.c +1 -1
@@ -341,7 +341,7 @@ static struct phy *phy_gmii_sel_of_xlate(struct device *dev,
  	if (priv->soc_data->features & BIT(PHY_GMII_SEL_RMII_IO_CLK_EN) &&
  	    args->args_count < 2)
  		return ERR_PTR(-EINVAL);
-	if (phy_id > priv->num_ports)
+	if (phy_id < 1 || phy_id > priv->num_ports)
  		return ERR_PTR(-EINVAL);
  	if (phy_id != priv->if_phys[phy_id - 1].id)
  		return ERR_PTR(-EINVAL);
maintainer Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

The "phy_id" comes from the device tree so it's going to be correct. But static checkers sometimes complain when we have an upper bounds check with no lower bounds check. Also it's a bit unusual that the lowest valid number is 1 instead of 0 so adding a check could potentially help someone.

[...]

Applied, thanks!

[1/1] phy: ti: gmii-sel: Add a sanity check on the phy_id

      commit: 9d3daf9ca3239042c2cf473a76db2a77e6de22c6

Best regards,

Signature · 1 line
~Vinod