]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
phy: ti: gmii-sel: Add a sanity check on the phy_id
authorDan Carpenter <dan.carpenter@linaro.org>
Fri, 17 Oct 2025 16:04:23 +0000 (19:04 +0300)
committerVinod Koul <vkoul@kernel.org>
Thu, 20 Nov 2025 16:54:35 +0000 (22:24 +0530)
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.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patch.msgid.link/aPJpB-QI8FMpFGOk@stanley.mountain
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/phy/ti/phy-gmii-sel.c

index 50adabb867cb12d317e806ba599a858dcd735da8..6cfe2538d15b12d27ed3a617ccfe03e0c211b779 100644 (file)
@@ -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);