Re: [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup

From: netdev-bot+sashiko

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


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit fixes two user-visible bugs but has no Fixes: tag and
no Cc: stable.
- [Low] The mux children (and the PHYs on them) are now torn down after
the EMAC has been put back into reset.

--

net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup

This patch moves registration of the sun8i MDIO mux out of
sun8i_dwmac_probe(), where it ran after stmmac_pltfr_probe() returned,
and into the new plat->mdio_init() hook. The mux now exists before
register_netdev(). Teardown moves from sun8i_dwmac_remove() into
plat->mdio_exit(), which runs after unregister_netdev().

> On remove, the mux goes away before
> unregister_netdev(), and unbinding with the link up oopses in
> phy_stop().
>
> Register and unregister the mux through the new mdio_init() and
> mdio_exit() hooks.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>

[Severity: Low]
The message describes two user-visible bugs: an early open that cannot
find the PHY, and an oops on unbind. There is no Fixes: tag and no
Cc: stable. Should these tags be added so the fix is picked up for
backporting?

The probe-side logic ("The mux must be registered after parent MDIO so
after stmmac_dvr_probe()") seems to come from commit 634db83b8265
("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs").

The remove-side ordering seems to come from commit 529254216773. That is
the ordering where sun8i_dwmac_remove() calls mdio_mux_uninit() before
stmmac_pltfr_remove().

A backport would also need the earlier patch "net: stmmac: Add MDIO init
and exit platform hooks". The message says "the new mdio_init() and
mdio_exit() hooks" but does not name that patch. Could the dependency be
named explicitly?

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 4acfda235394d..0ec25ae0b77ef 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

[ ... ]

> @@ -941,6 +940,13 @@ static int sun8i_dwmac_register_mdio_mux(struct stmmac_priv *priv)
> return ret;
> }
>
> +static void sun8i_dwmac_unregister_mdio_mux(struct stmmac_priv *priv)
> +{
> + struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
> +
> + mdio_mux_uninit(gmac->mux_handle);
> +}
> +

[ ... ]

> @@ -1269,9 +1251,6 @@ static void sun8i_dwmac_remove(struct platform_device *pdev)
> struct stmmac_priv *priv = netdev_priv(ndev);
> struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
>
> - if (gmac->variant->soc_has_internal_phy)
> - mdio_mux_uninit(gmac->mux_handle);
> -
> stmmac_pltfr_remove(pdev);

[Severity: Low]
With this change, stmmac_mdio_unregister() calls mdio_mux_uninit()
through plat->mdio_exit(). In stmmac_dvr_remove() that call comes after
the EMAC resets are asserted:

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);
...
}

Before this patch, sun8i_dwmac_remove() tore down the mux children while
the EMAC was still out of reset. On H3/H5, sunxi-h3-h5.dtsi supplies the
stmmaceth reset, so plat->stmmac_rst is non-NULL there.

Could MDIO accesses made while the PHYs behind the mux are being removed
now reach an EMAC held in reset? This happens with CONFIG_PHYLIB_LEDS
and a PHY driver that implements led_brightness_set. The path looks like
this:

stmmac_mdio_unregister()
sun8i_dwmac_unregister_mdio_mux()
mdio_mux_uninit()
mdiobus_unregister(child)
phy_remove()
phy_leds_unregister()
led_classdev_unregister() /* LED_OFF */
drv->led_brightness_set()
mdio_mux_write()
mdio_mux_syscon_switch_fn()
pb->mii_bus->write() /* stmmac MDIO write */

If the target child is not the one currently selected,
mdio_mux_syscon_switch_fn() also does more work against the block in
reset. It rewrites the syscon EPHY select bits, toggles internal EPHY
power, and calls sun8i_dwmac_reset(priv->ioaddr).

It is not verified what the hardware returns for reads from a block in
reset. If it returns 0, the MII busy-bit poll and the soft-reset poll
would pass at once and the PHY write would be dropped silently. The PHY
LED could then stay in its previous state after unbind.

The practical impact looks limited:

The only in-tree H3/H5 board with PHY LED nodes is
sun50i-h5-orangepi-pc2.dts. It uses an RTL8211E, and that realtek driver
entry has no led_brightness_set.

Other glue drivers already have the same reset-before-mdio_unregister
ordering for PHYs that sit directly on the stmmac bus.

sun8i_dwmac_exit() and sun8i_dwmac_unset_syscon() still reconcile EPHY
power and syscon afterwards.

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