[PATCH v2 net-next] net: stmmac: mdio: use phy_find_first to simplify stmmac_mdio_register

Simon Horman horms at kernel.org
Mon Oct 20 06:46:07 PDT 2025


On Sat, Oct 18, 2025 at 08:48:07PM +0200, Heiner Kallweit wrote:

...

> @@ -668,41 +669,31 @@ int stmmac_mdio_register(struct net_device *ndev)

...

> +	phydev = phy_find_first(new_bus);
> +	if (!phydev || phydev->mdio.addr > max_addr) {

Hi Heiner,

Depending on logic earlier in this function max_addr may be PHY_MAX_ADDR (32).

>  		dev_warn(dev, "No PHY found\n");
>  		err = -ENODEV;
>  		goto no_phy_found;
>  	}
>  
> +	/*
> +	 * If an IRQ was provided to be assigned after
> +	 * the bus probe, do it here.
> +	 */
> +	if (!mdio_bus_data->irqs && mdio_bus_data->probed_phy_irq > 0) {
> +		new_bus->irq[phydev->mdio.addr] = mdio_bus_data->probed_phy_irq;

And new_bus->irq is an array with PHY_MAX_ADDR elements.

So if phydev->mdio.addr and max_addr are both PHY_MAX_ADDR,
then the if condition above my first comment will not be met,
and it seems that the access would irq[] may overflow.

Perhaps this can't occur. But It does seem worth bringing to your attention.

Flagged by Smatch.

> +		phydev->irq = mdio_bus_data->probed_phy_irq;
> +	}
> +
> +	/*
> +	 * If we're going to bind the MAC to this PHY bus, and no PHY number
> +	 * was provided to the MAC, use the one probed here.
> +	 */
> +	if (priv->plat->phy_addr == -1)
> +		priv->plat->phy_addr = phydev->mdio.addr;
> +
> +	phy_attached_info(phydev);
> +
>  bus_register_done:
>  	priv->mii = new_bus;

...



More information about the linux-arm-kernel mailing list