Re: [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks

From: netdev-bot+sashiko

Date: Tue Nov 24 2026 - 06:16:42 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] stmmac_dvr_remove()
(drivers/net/ethernet/stmicro/stmmac/stmmac_main.c) asserts the MAC…

--

net: stmmac: Add MDIO init and exit platform hooks

This commit adds two platform hooks, mdio_init() and mdio_exit(), to
plat_stmmacenet_data. mdio_init() runs once the stmmac MDIO bus is
registered and mdio_exit() runs before it is unregistered. Glue drivers
can use them to add devices such as an MDIO mux on top of the bus.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 7396b68899c66..fb1f7b1a5323b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

[ ... ]

> @@ -703,6 +711,9 @@ int stmmac_mdio_unregister(struct net_device *ndev)
> if (!priv->mii)
> return 0;
>
> + if (priv->plat->mdio_exit)
> + priv->plat->mdio_exit(priv);
> +

[Severity: Medium]
Is the MDIO bus still usable when mdio_exit() runs on the remove path?

stmmac_dvr_remove() asserts the MAC resets before it calls
stmmac_mdio_unregister():

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_dvr_remove() {
...
phylink_destroy(priv->phylink);
if (priv->plat->stmmac_rst)
reset_control_assert(priv->plat->stmmac_rst);
reset_control_assert(priv->plat->stmmac_ahb_rst);

stmmac_pcs_clean(ndev);
stmmac_mdio_unregister(ndev);
...
}

As a result, mdio_exit() runs while the MAC, which is the MDIO master, is
held in reset.

Later in this series, dwmac-sun8i uses this hook to call mdio_mux_uninit().
That unregisters the mux child buses and removes the PHYs on them. PHY
removal can issue MDIO transactions through the mux:

stmmac_dvr_remove()
reset_control_assert(stmmac_rst)
stmmac_mdio_unregister()
mdio_exit() -> sun8i_dwmac_unregister_mdio_mux()
mdio_mux_uninit()
mdiobus_unregister(child)
phy_remove()
phy_leds_unregister()
led_classdev_unregister() -> phy_led_set_brightness()
phydev->drv->remove()

Each of these can reach mdio_mux_syscon_switch_fn(), which calls
sun8i_dwmac_reset() on the MAC registers, and then
stmmac_mdio_read_c22() or stmmac_mdio_write_c22(). The H3/H5 DT names
its EMAC reset "stmmaceth", so plat->stmmac_rst is asserted while this
happens.

With the register file in reset, the busy poll in stmmac_mdio_wait() can
read 0 and report the bus as idle:

if (readl_poll_timeout(reg, v, !(v & mask), 100, 10000))
return -EBUSY;

In that case, would MDIO writes be dropped without any error, and reads
return 0 as if they had succeeded? On interconnects that stall on
accesses to a block in reset, could the access hang instead?

Before this series, the sun8i mux teardown ran before
stmmac_pltfr_remove(), while the MAC was still out of reset. The commit
message says mdio_exit() is "called before it is unregistered", which
suggests the bus still works when the hook runs. The new member in
include/linux/stmmac.h does not mention any restriction either.

Should mdio_exit() be called before the resets are asserted in
stmmac_dvr_remove()? If not, should the hook document that the MDIO
master may be in reset when it runs?

> mdiobus_unregister(priv->mii);
> priv->mii->priv = NULL;
> mdiobus_free(priv->mii);

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sun8i-emac-mux-uaf-v4-0-57eba8915f25%40gmail.com