* [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering
@ 2026-11-20 10:45 Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
Chen-Yu Tsai pointed out that the probe error path and remove() put the
EPHY clock and reset before sun8i_dwmac_exit() uses them (patch 1).
Sashiko and Maxime Chevallier pointed out that the EPHY lookup and the
mux registration run after register_netdev(), and Maxime suggested
registering the mux in the MDIO setup (patches 2, 4 and 5). Patch 2
replaces "Defer probe when the EPHY clock is not ready" [1]. Patch 3
balances runtime PM on the stmmac probe error path, which a mux failure
now takes.
Tested on QEMU orangepi-pc (H3, internal PHY) with KASAN; I have no H3,
H5 or V3s board. On net-next, a test-only mdio_mux_init() failure gives
a KASAN use-after-free in clk_disable() from sun8i_dwmac_exit(), and
unbinding with the link up oopses in phy_stop(). With the series both
are clean, a test device tree whose EPHY clock has no provider
(fw_devlink=permissive) defers before the netdev exists, and three
unbind/bind cycles with the link up pass. Without patch 3, after the
failed probe and a rebind the MAC stays runtime active with usage count
1; with it the MAC runtime-suspends (usage 0).
Developed with Claude (Anthropic); I reviewed it.
[1] https://lore.kernel.org/r/20261113-b4-sun8i-emac-ephy-defer-v1-1-12a8591702fe@gmail.com
---
Changes in v4:
- Put the EPHY clock and reset after stmmac_pltfr_remove() (Chen-Yu Tsai)
- Get the EPHY clock and reset before the MAC probe, defer on the clock (Sashiko, Maxime Chevallier)
- Balance runtime PM when the stmmac probe fails (new patch 3)
- Register the mux through new stmmac mdio_init()/mdio_exit() hooks (Maxime Chevallier)
- Now a series, new cover subject
- Link to v3: https://patch.msgid.link/20261115-sun8i-emac-mux-uaf-v3-1-c69d4189539d@gmail.com
Changes in v3:
- Drop the Fixes tag (Andrew Lunn)
- Shorter commit message
- Link to v2: https://patch.msgid.link/20261113-sun8i-emac-mux-uaf-v2-1-6203666b2687@gmail.com
Changes in v2:
- Target net-next instead of net, drop Cc: stable (Andrew Lunn)
- Shorter commit message
- Rebased onto net-next
- Link to v1: https://patch.msgid.link/20261112-sun8i-emac-mux-uaf-v1-1-308ae7e6fcf2@gmail.com
---
Arun Iyengar (5):
net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
net: stmmac: Balance runtime PM when the probe fails
net: stmmac: Add MDIO init and exit platform hooks
net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 82 +++++++++--------------
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 11 +++
include/linux/stmmac.h | 2 +
4 files changed, 48 insertions(+), 49 deletions(-)
---
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
change-id: 20261112-sun8i-emac-mux-uaf-1ba885219fee
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
@ 2026-11-20 10:45 ` Arun Iyengar via B4 Relay
2026-11-22 16:47 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Arun Iyengar via B4 Relay
` (3 subsequent siblings)
4 siblings, 2 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
sun8i_dwmac_exit() unpowers the internal PHY through ephy_clk and
rst_ephy, but the probe error path and sun8i_dwmac_remove() put both
before stmmac_pltfr_remove() calls it. If mdio_mux_init() fails after
the scan of the internal bus has powered the PHY, this is a
use-after-free.
Put them after stmmac_pltfr_remove(). The explicit unpower in remove()
is then redundant.
Suggested-by: Chen-Yu Tsai <wens@kernel.org>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 2ece7ba9dd73..9fb398f7cf9e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1236,7 +1236,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
ret = sun8i_dwmac_register_mdio_mux(priv);
if (ret) {
dev_err(&pdev->dev, "Failed to register mux\n");
- goto dwmac_mux;
+ goto dwmac_remove;
}
}
@@ -1244,12 +1244,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
return 0;
-dwmac_mux:
- reset_control_put(gmac->rst_ephy);
- clk_put(gmac->ephy_clk);
dwmac_remove:
pm_runtime_put_noidle(&pdev->dev);
stmmac_pltfr_remove(pdev);
+ reset_control_put(gmac->rst_ephy);
+ clk_put(gmac->ephy_clk);
dwmac_syscon:
sun8i_dwmac_unset_syscon(gmac);
@@ -1262,14 +1261,12 @@ 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) {
+ if (gmac->variant->soc_has_internal_phy)
mdio_mux_uninit(gmac->mux_handle);
- sun8i_dwmac_unpower_internal_phy(gmac);
- reset_control_put(gmac->rst_ephy);
- clk_put(gmac->ephy_clk);
- }
stmmac_pltfr_remove(pdev);
+ reset_control_put(gmac->rst_ephy);
+ clk_put(gmac->ephy_clk);
sun8i_dwmac_unset_syscon(gmac);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
@ 2026-11-20 10:45 ` Arun Iyengar via B4 Relay
2026-11-22 16:51 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
` (2 subsequent siblings)
4 siblings, 2 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
get_ephy_nodes() runs after stmmac_pltfr_probe() has registered the
netdev, so its -EPROBE_DEFER comes too late. An EPHY clock that is not
ready yet does not defer at all: the node is skipped and the probe
fails with -ENODEV.
Look up the clock and reset before stmmac_pltfr_probe(), and defer on
the clock as on the reset.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 34 ++++++++++++++---------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 9fb398f7cf9e..4acfda235394 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -775,16 +775,15 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
}
/* Search in mdio-mux node for internal PHY node and get its clk/reset */
-static int get_ephy_nodes(struct stmmac_priv *priv)
+static int get_ephy_nodes(struct device *dev, struct sunxi_priv_data *gmac)
{
- struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
struct device_node *mdio_internal;
struct device_node *mdio_mux;
int ret;
- mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux");
+ mdio_mux = of_get_child_by_name(dev->of_node, "mdio-mux");
if (!mdio_mux) {
- dev_err(priv->device, "Cannot get mdio-mux node\n");
+ dev_err(dev, "Cannot get mdio-mux node\n");
return -ENODEV;
}
@@ -792,7 +791,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
"allwinner,sun8i-h3-mdio-internal");
of_node_put(mdio_mux);
if (!mdio_internal) {
- dev_err(priv->device, "Cannot get internal_mdio node\n");
+ dev_err(dev, "Cannot get internal_mdio node\n");
return -ENODEV;
}
@@ -801,8 +800,13 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
struct clk *ephy_clk;
ephy_clk = of_clk_get(iphynode, 0);
- if (IS_ERR(ephy_clk))
+ if (IS_ERR(ephy_clk)) {
+ if (PTR_ERR(ephy_clk) == -EPROBE_DEFER) {
+ of_node_put(mdio_internal);
+ return -EPROBE_DEFER;
+ }
continue;
+ }
gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL);
if (IS_ERR(gmac->rst_ephy)) {
ret = PTR_ERR(gmac->rst_ephy);
@@ -814,7 +818,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
continue;
}
gmac->ephy_clk = ephy_clk;
- dev_info(priv->device, "Found internal PHY node\n");
+ dev_info(dev, "Found internal PHY node\n");
of_node_put(mdio_internal);
return 0;
}
@@ -1209,9 +1213,15 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
plat_dat->tx_fifo_size = 4096;
plat_dat->rx_fifo_size = 16384;
+ if (gmac->variant->soc_has_internal_phy) {
+ ret = get_ephy_nodes(dev, gmac);
+ if (ret)
+ return ret;
+ }
+
ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
if (ret)
- return ret;
+ goto dwmac_ephy;
ret = stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
if (ret)
@@ -1230,9 +1240,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
* so after stmmac_dvr_probe()
*/
if (gmac->variant->soc_has_internal_phy) {
- ret = get_ephy_nodes(priv);
- if (ret)
- goto dwmac_remove;
ret = sun8i_dwmac_register_mdio_mux(priv);
if (ret) {
dev_err(&pdev->dev, "Failed to register mux\n");
@@ -1247,10 +1254,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
dwmac_remove:
pm_runtime_put_noidle(&pdev->dev);
stmmac_pltfr_remove(pdev);
- reset_control_put(gmac->rst_ephy);
- clk_put(gmac->ephy_clk);
dwmac_syscon:
sun8i_dwmac_unset_syscon(gmac);
+dwmac_ephy:
+ reset_control_put(gmac->rst_ephy);
+ clk_put(gmac->ephy_clk);
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Arun Iyengar via B4 Relay
@ 2026-11-20 10:45 ` Arun Iyengar via B4 Relay
2026-11-22 17:03 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
4 siblings, 2 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
__stmmac_dvr_probe() enables runtime PM and takes a usage count before
it registers the MDIO bus, but its error path undoes neither. After a
failed or deferred probe the device never runtime-suspends.
Undo both, as stmmac_dvr_remove() does.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f256244ce0d1..4ebf4b625374 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -8407,6 +8407,8 @@ static int __stmmac_dvr_probe(struct device *device,
error_pcs_setup:
stmmac_mdio_unregister(ndev);
error_mdio_register:
+ pm_runtime_disable(device);
+ pm_runtime_put_noidle(device);
stmmac_napi_del(ndev);
error_hw_init:
destroy_workqueue(priv->wq);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
` (2 preceding siblings ...)
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
@ 2026-11-20 10:45 ` Arun Iyengar via B4 Relay
2026-11-22 17:05 ` Maxime Chevallier
` (2 more replies)
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
4 siblings, 3 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
A glue driver that adds devices on top of the stmmac MDIO bus, such as
an MDIO mux, can only do so after stmmac_dvr_probe() has registered the
netdev.
Add mdio_init(), called once the bus is registered, and mdio_exit(),
called before it is unregistered.
Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 11 +++++++++++
include/linux/stmmac.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 7396b68899c6..fb1f7b1a5323 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -682,8 +682,16 @@ int stmmac_mdio_register(struct net_device *ndev)
bus_register_done:
priv->mii = new_bus;
+ if (priv->plat->mdio_init) {
+ err = priv->plat->mdio_init(priv);
+ if (err)
+ goto mdio_init_fail;
+ }
+
return 0;
+mdio_init_fail:
+ priv->mii = NULL;
no_phy_found:
mdiobus_unregister(new_bus);
bus_register_fail:
@@ -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);
+
mdiobus_unregister(priv->mii);
priv->mii->priv = NULL;
mdiobus_free(priv->mii);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 00be2df63d22..e94f9cab973d 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -296,6 +296,8 @@ struct plat_stmmacenet_data {
int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
void *ctx);
void (*dump_debug_regs)(void *priv);
+ int (*mdio_init)(struct stmmac_priv *priv);
+ void (*mdio_exit)(struct stmmac_priv *priv);
int (*pcs_init)(struct stmmac_priv *priv);
void (*pcs_exit)(struct stmmac_priv *priv);
struct phylink_pcs *(*select_pcs)(struct stmmac_priv *priv,
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
` (3 preceding siblings ...)
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
@ 2026-11-20 10:45 ` Arun Iyengar via B4 Relay
2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
4 siblings, 2 replies; 17+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 10:45 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
Both PHYs sit behind the mux, but the mux is registered only after
stmmac_pltfr_probe() has registered the netdev, so an early open does
not find the PHY. 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@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 41 ++++++-----------------
1 file changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 4acfda235394..0ec25ae0b77e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -17,7 +17,6 @@
#include <linux/of_platform.h>
#include <linux/phy.h>
#include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <linux/regmap.h>
#include <linux/stmmac.h>
@@ -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);
+}
+
static int sun8i_dwmac_set_syscon(struct device *dev,
struct plat_stmmacenet_data *plat)
{
@@ -1133,8 +1139,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
struct stmmac_resources stmmac_res;
struct sunxi_priv_data *gmac;
struct device *dev = &pdev->dev;
- struct stmmac_priv *priv;
- struct net_device *ndev;
struct regmap *regmap;
int ret;
@@ -1217,6 +1221,9 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
ret = get_ephy_nodes(dev, gmac);
if (ret)
return ret;
+
+ plat_dat->mdio_init = sun8i_dwmac_register_mdio_mux;
+ plat_dat->mdio_exit = sun8i_dwmac_unregister_mdio_mux;
}
ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
@@ -1227,33 +1234,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
if (ret)
goto dwmac_syscon;
- ndev = dev_get_drvdata(&pdev->dev);
- priv = netdev_priv(ndev);
-
- /* the MAC is runtime suspended after stmmac_dvr_probe(), so we
- * need to ensure the MAC resume back before other operations such
- * as reset.
- */
- pm_runtime_get_sync(&pdev->dev);
-
- /* The mux must be registered after parent MDIO
- * so after stmmac_dvr_probe()
- */
- if (gmac->variant->soc_has_internal_phy) {
- ret = sun8i_dwmac_register_mdio_mux(priv);
- if (ret) {
- dev_err(&pdev->dev, "Failed to register mux\n");
- goto dwmac_remove;
- }
- }
-
- pm_runtime_put(&pdev->dev);
-
return 0;
-dwmac_remove:
- pm_runtime_put_noidle(&pdev->dev);
- stmmac_pltfr_remove(pdev);
dwmac_syscon:
sun8i_dwmac_unset_syscon(gmac);
dwmac_ephy:
@@ -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);
reset_control_put(gmac->rst_ephy);
clk_put(gmac->ephy_clk);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
@ 2026-11-22 16:47 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 16:47 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
Hi,
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> sun8i_dwmac_exit() unpowers the internal PHY through ephy_clk and
> rst_ephy, but the probe error path and sun8i_dwmac_remove() put both
> before stmmac_pltfr_remove() calls it. If mdio_mux_init() fails after
> the scan of the internal bus has powered the PHY, this is a
> use-after-free.
>
> Put them after stmmac_pltfr_remove(). The explicit unpower in remove()
> is then redundant.
>
> Suggested-by: Chen-Yu Tsai <wens@kernel.org>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 2ece7ba9dd73..9fb398f7cf9e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -1236,7 +1236,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> ret = sun8i_dwmac_register_mdio_mux(priv);
> if (ret) {
> dev_err(&pdev->dev, "Failed to register mux\n");
> - goto dwmac_mux;
> + goto dwmac_remove;
> }
> }
>
> @@ -1244,12 +1244,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
>
> return 0;
>
> -dwmac_mux:
> - reset_control_put(gmac->rst_ephy);
> - clk_put(gmac->ephy_clk);
> dwmac_remove:
> pm_runtime_put_noidle(&pdev->dev);
> stmmac_pltfr_remove(pdev);
> + reset_control_put(gmac->rst_ephy);
> + clk_put(gmac->ephy_clk);
> dwmac_syscon:
> sun8i_dwmac_unset_syscon(gmac);
>
> @@ -1262,14 +1261,12 @@ 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) {
> + if (gmac->variant->soc_has_internal_phy)
> mdio_mux_uninit(gmac->mux_handle);
> - sun8i_dwmac_unpower_internal_phy(gmac);
> - reset_control_put(gmac->rst_ephy);
> - clk_put(gmac->ephy_clk);
> - }
>
> stmmac_pltfr_remove(pdev);
> + reset_control_put(gmac->rst_ephy);
> + clk_put(gmac->ephy_clk);
> sun8i_dwmac_unset_syscon(gmac);
> }
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
2026-11-20 10:45 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Arun Iyengar via B4 Relay
@ 2026-11-22 16:51 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 16:51 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
Hi,
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> get_ephy_nodes() runs after stmmac_pltfr_probe() has registered the
> netdev, so its -EPROBE_DEFER comes too late. An EPHY clock that is not
> ready yet does not defer at all: the node is skipped and the probe
> fails with -ENODEV.
>
> Look up the clock and reset before stmmac_pltfr_probe(), and defer on
> the clock as on the reset.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
This is a step in the right direction, thanks
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 34 ++++++++++++++---------
> 1 file changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 9fb398f7cf9e..4acfda235394 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -775,16 +775,15 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
> }
>
> /* Search in mdio-mux node for internal PHY node and get its clk/reset */
> -static int get_ephy_nodes(struct stmmac_priv *priv)
> +static int get_ephy_nodes(struct device *dev, struct sunxi_priv_data *gmac)
> {
> - struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
> struct device_node *mdio_internal;
> struct device_node *mdio_mux;
> int ret;
>
> - mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux");
> + mdio_mux = of_get_child_by_name(dev->of_node, "mdio-mux");
> if (!mdio_mux) {
> - dev_err(priv->device, "Cannot get mdio-mux node\n");
> + dev_err(dev, "Cannot get mdio-mux node\n");
> return -ENODEV;
> }
>
> @@ -792,7 +791,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
> "allwinner,sun8i-h3-mdio-internal");
> of_node_put(mdio_mux);
> if (!mdio_internal) {
> - dev_err(priv->device, "Cannot get internal_mdio node\n");
> + dev_err(dev, "Cannot get internal_mdio node\n");
> return -ENODEV;
> }
>
> @@ -801,8 +800,13 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
> struct clk *ephy_clk;
>
> ephy_clk = of_clk_get(iphynode, 0);
> - if (IS_ERR(ephy_clk))
> + if (IS_ERR(ephy_clk)) {
> + if (PTR_ERR(ephy_clk) == -EPROBE_DEFER) {
> + of_node_put(mdio_internal);
> + return -EPROBE_DEFER;
> + }
> continue;
> + }
> gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL);
> if (IS_ERR(gmac->rst_ephy)) {
> ret = PTR_ERR(gmac->rst_ephy);
> @@ -814,7 +818,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
> continue;
> }
> gmac->ephy_clk = ephy_clk;
> - dev_info(priv->device, "Found internal PHY node\n");
> + dev_info(dev, "Found internal PHY node\n");
> of_node_put(mdio_internal);
> return 0;
> }
> @@ -1209,9 +1213,15 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> plat_dat->tx_fifo_size = 4096;
> plat_dat->rx_fifo_size = 16384;
>
> + if (gmac->variant->soc_has_internal_phy) {
> + ret = get_ephy_nodes(dev, gmac);
> + if (ret)
> + return ret;
> + }
> +
> ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
> if (ret)
> - return ret;
> + goto dwmac_ephy;
>
> ret = stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
> if (ret)
> @@ -1230,9 +1240,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> * so after stmmac_dvr_probe()
> */
> if (gmac->variant->soc_has_internal_phy) {
> - ret = get_ephy_nodes(priv);
> - if (ret)
> - goto dwmac_remove;
> ret = sun8i_dwmac_register_mdio_mux(priv);
> if (ret) {
> dev_err(&pdev->dev, "Failed to register mux\n");
> @@ -1247,10 +1254,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> dwmac_remove:
> pm_runtime_put_noidle(&pdev->dev);
> stmmac_pltfr_remove(pdev);
> - reset_control_put(gmac->rst_ephy);
> - clk_put(gmac->ephy_clk);
> dwmac_syscon:
> sun8i_dwmac_unset_syscon(gmac);
> +dwmac_ephy:
> + reset_control_put(gmac->rst_ephy);
> + clk_put(gmac->ephy_clk);
>
> return ret;
> }
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
@ 2026-11-22 17:03 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 17:03 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> __stmmac_dvr_probe() enables runtime PM and takes a usage count before
> it registers the MDIO bus, but its error path undoes neither. After a
> failed or deferred probe the device never runtime-suspends.
>
> Undo both, as stmmac_dvr_remove() does.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index f256244ce0d1..4ebf4b625374 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -8407,6 +8407,8 @@ static int __stmmac_dvr_probe(struct device *device,
> error_pcs_setup:
> stmmac_mdio_unregister(ndev);
> error_mdio_register:
> + pm_runtime_disable(device);
Note that in __stmmac_dvr_probe(), we enable runtime PM with:
if (!pm_runtime_enabled(device))
pm_runtime_enable(device);
And I discovered painfully this weekend that on PCIe (dwmac-motorcomm), the PCI bus
does a pm_runtime_enable on the device before probing, so here we'd have a mismatch.
OTOH there's no easy way around that. The proper way would be to get rid of that PM
handling in __stmmac_dvr_probe() and do that closer to the bus (so, in the stmmac
platform code for non-PCI devices) but lots of glues are currently bypassing this...
We're trading one unbalance for another one, but I'd say let's go with this for
now, and we can then properly deal with PM driver-wide.
Let's see what sashiko says too.
Maxime
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
@ 2026-11-22 17:05 ` Maxime Chevallier
2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2 siblings, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 17:05 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
Hi,
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> A glue driver that adds devices on top of the stmmac MDIO bus, such as
> an MDIO mux, can only do so after stmmac_dvr_probe() has registered the
> netdev.
>
> Add mdio_init(), called once the bus is registered, and mdio_exit(),
> called before it is unregistered.
>
> Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 11 +++++++++++
> include/linux/stmmac.h | 2 ++
> 2 files changed, 13 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 7396b68899c6..fb1f7b1a5323 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -682,8 +682,16 @@ int stmmac_mdio_register(struct net_device *ndev)
> bus_register_done:
> priv->mii = new_bus;
>
> + if (priv->plat->mdio_init) {
> + err = priv->plat->mdio_init(priv);
> + if (err)
> + goto mdio_init_fail;
> + }
> +
> return 0;
>
> +mdio_init_fail:
> + priv->mii = NULL;
> no_phy_found:
> mdiobus_unregister(new_bus);
> bus_register_fail:
> @@ -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);
> +
> mdiobus_unregister(priv->mii);
> priv->mii->priv = NULL;
> mdiobus_free(priv->mii);
> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 00be2df63d22..e94f9cab973d 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -296,6 +296,8 @@ struct plat_stmmacenet_data {
> int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
> void *ctx);
> void (*dump_debug_regs)(void *priv);
> + int (*mdio_init)(struct stmmac_priv *priv);
> + void (*mdio_exit)(struct stmmac_priv *priv);
> int (*pcs_init)(struct stmmac_priv *priv);
> void (*pcs_exit)(struct stmmac_priv *priv);
> struct phylink_pcs *(*select_pcs)(struct stmmac_priv *priv,
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
@ 2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 17:35 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
Hi,
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> Both PHYs sit behind the mux, but the mux is registered only after
> stmmac_pltfr_probe() has registered the netdev, so an early open does
> not find the PHY. 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@gmail.com>
Looks good, I tested that on Allwinner H2+, the mux probes fine. This
has run on the stmmac netdevCI anyways and no breakage reported on
other plaftorms.
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 41 ++++++-----------------
> 1 file changed, 10 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 4acfda235394..0ec25ae0b77e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -17,7 +17,6 @@
> #include <linux/of_platform.h>
> #include <linux/phy.h>
> #include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
> #include <linux/regulator/consumer.h>
> #include <linux/regmap.h>
> #include <linux/stmmac.h>
> @@ -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);
> +}
> +
> static int sun8i_dwmac_set_syscon(struct device *dev,
> struct plat_stmmacenet_data *plat)
> {
> @@ -1133,8 +1139,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> struct stmmac_resources stmmac_res;
> struct sunxi_priv_data *gmac;
> struct device *dev = &pdev->dev;
> - struct stmmac_priv *priv;
> - struct net_device *ndev;
> struct regmap *regmap;
> int ret;
>
> @@ -1217,6 +1221,9 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> ret = get_ephy_nodes(dev, gmac);
> if (ret)
> return ret;
> +
> + plat_dat->mdio_init = sun8i_dwmac_register_mdio_mux;
> + plat_dat->mdio_exit = sun8i_dwmac_unregister_mdio_mux;
> }
>
> ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
> @@ -1227,33 +1234,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> if (ret)
> goto dwmac_syscon;
>
> - ndev = dev_get_drvdata(&pdev->dev);
> - priv = netdev_priv(ndev);
> -
> - /* the MAC is runtime suspended after stmmac_dvr_probe(), so we
> - * need to ensure the MAC resume back before other operations such
> - * as reset.
> - */
> - pm_runtime_get_sync(&pdev->dev);
> -
> - /* The mux must be registered after parent MDIO
> - * so after stmmac_dvr_probe()
> - */
> - if (gmac->variant->soc_has_internal_phy) {
> - ret = sun8i_dwmac_register_mdio_mux(priv);
> - if (ret) {
> - dev_err(&pdev->dev, "Failed to register mux\n");
> - goto dwmac_remove;
> - }
> - }
> -
> - pm_runtime_put(&pdev->dev);
> -
> return 0;
>
> -dwmac_remove:
> - pm_runtime_put_noidle(&pdev->dev);
> - stmmac_pltfr_remove(pdev);
> dwmac_syscon:
> sun8i_dwmac_unset_syscon(gmac);
> dwmac_ephy:
> @@ -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);
> reset_control_put(gmac->rst_ephy);
> clk_put(gmac->ephy_clk);
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
2026-11-22 17:05 ` Maxime Chevallier
@ 2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2 siblings, 0 replies; 17+ messages in thread
From: Maxime Chevallier @ 2026-11-22 17:35 UTC (permalink / raw)
To: aiyengar1990, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Philipp Zabel,
Russell King
Cc: netdev, linux-arm-kernel, linux-sunxi, linux-stm32, linux-kernel
Hi again,
On 11/20/26 11:45, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> A glue driver that adds devices on top of the stmmac MDIO bus, such as
> an MDIO mux, can only do so after stmmac_dvr_probe() has registered the
> netdev.
>
> Add mdio_init(), called once the bus is registered, and mdio_exit(),
> called before it is unregistered.
>
> Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
Manually tested on H2+,
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 11 +++++++++++
> include/linux/stmmac.h | 2 ++
> 2 files changed, 13 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 7396b68899c6..fb1f7b1a5323 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -682,8 +682,16 @@ int stmmac_mdio_register(struct net_device *ndev)
> bus_register_done:
> priv->mii = new_bus;
>
> + if (priv->plat->mdio_init) {
> + err = priv->plat->mdio_init(priv);
> + if (err)
> + goto mdio_init_fail;
> + }
> +
> return 0;
>
> +mdio_init_fail:
> + priv->mii = NULL;
> no_phy_found:
> mdiobus_unregister(new_bus);
> bus_register_fail:
> @@ -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);
> +
> mdiobus_unregister(priv->mii);
> priv->mii->priv = NULL;
> mdiobus_free(priv->mii);
> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 00be2df63d22..e94f9cab973d 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -296,6 +296,8 @@ struct plat_stmmacenet_data {
> int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
> void *ctx);
> void (*dump_debug_regs)(void *priv);
> + int (*mdio_init)(struct stmmac_priv *priv);
> + void (*mdio_exit)(struct stmmac_priv *priv);
> int (*pcs_init)(struct stmmac_priv *priv);
> void (*pcs_exit)(struct stmmac_priv *priv);
> struct phylink_pcs *(*select_pcs)(struct stmmac_priv *priv,
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
2026-11-22 16:47 ` Maxime Chevallier
@ 2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 11:16 UTC (permalink / raw)
To: aiyengar1990
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
p.zabel, linux, netdev, linux-arm-kernel, linux-sunxi,
linux-stm32, linux-kernel
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 a real use-after-free on the sun8i_dwmac_probe()
error path but has no Fixes: tag and no Cc: stable, so stable trees…
--
net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
This commit moves the reset_control_put() and clk_put() calls for the
internal PHY so they run after stmmac_pltfr_remove(). Before, they ran
before it, both on the sun8i_dwmac_probe() mdio-mux error path and in
sun8i_dwmac_remove(). This fixes a use-after-free because
sun8i_dwmac_exit() still uses ephy_clk and rst_ephy to unpower the
internal PHY.
> net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC
>
> sun8i_dwmac_exit() unpowers the internal PHY through ephy_clk and
> rst_ephy, but the probe error path and sun8i_dwmac_remove() put both
> before stmmac_pltfr_remove() calls it. If mdio_mux_init() fails after
> the scan of the internal bus has powered the PHY, this is a
> use-after-free.
>
> Put them after stmmac_pltfr_remove(). The explicit unpower in remove()
> is then redundant.
>
> Suggested-by: Chen-Yu Tsai <wens@kernel.org>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
[Severity: Low]
Should this have a Fixes: tag, and perhaps Cc: stable? Without them, the
stable trees won't pick up the use-after-free fix automatically.
The ordering problem seems to come from commit 529254216773 ("net: stmmac:
dwmac-sun8i: Balance internal PHY resource references"). That commit added
the puts under the dwmac_mux label, and that error path then called
sun8i_dwmac_exit() explicitly.
Today, the same error path falls through to:
stmmac_pltfr_remove()->stmmac_dvr_remove()->sun8i_dwmac_exit()
->sun8i_dwmac_unpower_internal_phy()
When internal_phy_powered is true, that runs clk_disable_unprepare() and
reset_control_assert() on handles that have already been released.
The flag can be true here. mdio_mux_init() scans the internal bus first,
and mdio_mux_syscon_switch_fn()->sun8i_dwmac_power_internal_phy() sets it.
A later child bus can then fail with -EPROBE_DEFER, which is an ordinary
event.
Would something like this be appropriate?
Fixes: 529254216773 ("net: stmmac: dwmac-sun8i: Balance internal PHY resource references")
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 2ece7ba9dd73b..9fb398f7cf9ec 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -1236,7 +1236,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> ret = sun8i_dwmac_register_mdio_mux(priv);
> if (ret) {
> dev_err(&pdev->dev, "Failed to register mux\n");
> - goto dwmac_mux;
> + goto dwmac_remove;
> }
> }
>
> @@ -1244,12 +1244,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
>
> return 0;
>
> -dwmac_mux:
> - reset_control_put(gmac->rst_ephy);
> - clk_put(gmac->ephy_clk);
> dwmac_remove:
> pm_runtime_put_noidle(&pdev->dev);
> stmmac_pltfr_remove(pdev);
> + reset_control_put(gmac->rst_ephy);
> + clk_put(gmac->ephy_clk);
> dwmac_syscon:
> sun8i_dwmac_unset_syscon(gmac);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sun8i-emac-mux-uaf-v4-0-57eba8915f25%40gmail.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
2026-11-20 10:45 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Arun Iyengar via B4 Relay
2026-11-22 16:51 ` Maxime Chevallier
@ 2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 11:16 UTC (permalink / raw)
To: aiyengar1990
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
p.zabel, linux, netdev, linux-arm-kernel, linux-sunxi,
linux-stm32, linux-kernel
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 message describes two failures as real bugs: "its
-EPROBE_DEFER comes too late", and "an EPHY clock that is not ready…
- [Low] The concern: the patch fixes a real, user-visible probe failure
(-ENODEV instead of -EPROBE_DEFER when the EPHY clock provider is not…
Pre-existing issues:
- [Low] The concern: for allwinner,sun8i-h3-emac and
allwinner,sun8i-v3s-emac, the DT binding makes the mdio-mux node…
--
net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe
This moves the internal PHY clock and reset lookup in get_ephy_nodes()
ahead of stmmac_pltfr_probe() in sun8i_dwmac_probe(). It also makes an
-EPROBE_DEFER from of_clk_get() on the EPHY node defer the probe instead
of skipping the node, and reorders the error unwinding so the EPHY clock
and reset are released on every failure path.
> get_ephy_nodes() runs after stmmac_pltfr_probe() has registered the
> netdev, so its -EPROBE_DEFER comes too late. An EPHY clock that is not
> ready yet does not defer at all: the node is skipped and the probe
> fails with -ENODEV.
[Severity: Low]
Can either of these failures happen on the in-tree device trees that use
this path (sunxi-h3-h5.dtsi and sun8i-v3s.dtsi)?
On those device trees, the EMAC's own "stmmaceth" reset and the internal
PHY's clock and reset all come from the same &ccu node:
arch/arm/boot/dts/allwinner/sunxi-h3-h5.dtsi, emac:
resets = <&ccu RST_BUS_EMAC>;
reset-names = "stmmaceth";
arch/arm/boot/dts/allwinner/sunxi-h3-h5.dtsi, internal_mdio ethernet-phy@1:
clocks = <&ccu CLK_BUS_EPHY>;
resets = <&ccu RST_BUS_EPHY>;
devm_stmmac_probe_config_dt() runs before get_ephy_nodes() in both the
old and the new code. Its reset lookup already returns -EPROBE_DEFER
until the CCU reset controller is registered, even though the reset is
optional:
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c:stmmac_probe_config_dt() {
...
plat->stmmac_rst = devm_reset_control_get_optional(&pdev->dev,
STMMAC_RESOURCE_NAME);
...
}
sunxi_ccu_probe() registers the clock provider before the reset
controller. If reset registration fails, it removes the clock provider
again:
drivers/clk/sunxi-ng/ccu_common.c:sunxi_ccu_probe() {
...
ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
desc->hw_clks);
...
ret = reset_controller_register(&reset->rcdev);
if (ret)
goto err_del_provider;
...
}
So by the time get_ephy_nodes() runs, it doesn't look like of_clk_get()
or of_reset_control_get_exclusive() on the EPHY node can return
-EPROBE_DEFER.
The message also leaves out what looks like the real reason for moving
the lookup. With the later "net: stmmac: dwmac-sun8i: Register the MDIO
mux in the MDIO setup" change, sun8i_dwmac_register_mdio_mux() becomes
plat_dat->mdio_init and runs inside stmmac_pltfr_probe(). From there,
mdio_mux_syscon_switch_fn()->sun8i_dwmac_power_internal_phy() uses
gmac->ephy_clk and gmac->rst_ephy, so both have to be looked up first.
Could the commit message describe this as preparation for that change,
and as hardening for device trees where the EPHY clock or reset come from
a different provider, rather than as a fix for a probe failure?
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 9fb398f7cf9ec..4acfda235394d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
[ ... ]
> @@ -801,8 +800,13 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
> struct clk *ephy_clk;
>
> ephy_clk = of_clk_get(iphynode, 0);
> - if (IS_ERR(ephy_clk))
> + if (IS_ERR(ephy_clk)) {
> + if (PTR_ERR(ephy_clk) == -EPROBE_DEFER) {
> + of_node_put(mdio_internal);
> + return -EPROBE_DEFER;
> + }
> continue;
> + }
[Severity: Low]
The commit message presents this as a fix for a probe that fails with
-ENODEV instead of deferring. If that is the intent, should it carry a
Fixes: tag?
Based on the ordering described above, though, the old continue only
turns a deferral into -ENODEV when the EPHY clock comes from a different
provider than the EMAC's "stmmaceth" reset. That seems to be possible
only with out-of-tree device trees. If so, rewording the commit message
may fit better than adding a Fixes: tag.
[ ... ]
> @@ -1209,9 +1213,15 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
> plat_dat->tx_fifo_size = 4096;
> plat_dat->rx_fifo_size = 16384;
>
> + if (gmac->variant->soc_has_internal_phy) {
> + ret = get_ephy_nodes(dev, gmac);
> + if (ret)
> + return ret;
> + }
[Severity: Low]
This isn't a bug introduced by this patch, but should a missing mdio-mux
node fail the whole probe on allwinner,sun8i-h3-emac and
allwinner,sun8i-v3s-emac?
In allwinner,sun8i-a83t-emac.yaml, mdio-mux appears only under the
h3/v3s properties clause. It is not in the required list, and no
ethernet-phy child of the internal MDIO bus is required either. Even so,
get_ephy_nodes() returns -ENODEV when the node is missing:
mdio_mux = of_get_child_by_name(dev->of_node, "mdio-mux");
if (!mdio_mux) {
dev_err(dev, "Cannot get mdio-mux node\n");
return -ENODEV;
}
It does the same when there is no allwinner,sun8i-h3-mdio-internal
child, or when no child has a usable clock.
So an H3 or V3s board that the binding allows, using only an external
PHY and no mdio-mux, fails to probe. Before this patch the same error
took the goto dwmac_remove path, so the result was the same. This change
only moves the check earlier.
> ret = sun8i_dwmac_set_syscon(&pdev->dev, plat_dat);
> if (ret)
> - return ret;
> + goto dwmac_ephy;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sun8i-emac-mux-uaf-v4-0-57eba8915f25%40gmail.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
2026-11-22 17:03 ` Maxime Chevallier
@ 2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 11:16 UTC (permalink / raw)
To: aiyengar1990
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
p.zabel, linux, netdev, linux-arm-kernel, linux-sunxi,
linux-stm32, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 1
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).
- [High] In __stmmac_dvr_probe()
(drivers/net/ethernet/stmicro/stmmac/stmmac_main.c), the patch adds an…
- [Low] The patch fixes a real, user-visible runtime-PM bug in
__stmmac_dvr_probe() but has no Fixes: tag.
Pre-existing issues:
- [Medium] Before stmmac_hw_init(), __stmmac_dvr_probe() asserts and then
deasserts priv->plat->stmmac_rst, and deasserts the shared…
--
net: stmmac: Balance runtime PM when the probe fails
This adds pm_runtime_disable() and pm_runtime_put_noidle() at the
error_mdio_register label in __stmmac_dvr_probe(). A failed or deferred
probe then undoes the runtime PM enable and the usage count taken before
stmmac_mdio_register(), the same way stmmac_dvr_remove() does.
> Undo both, as stmmac_dvr_remove() does.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
[Severity: Low]
Should this have a Fixes: tag?
Commit 5ec55823438e ("net: stmmac: add clocks management for gmac
driver") added the pm_runtime_get_noresume(), pm_runtime_set_active()
and pm_runtime_enable() sequence to __stmmac_dvr_probe(). The only
matching pm_runtime_put() is on the success path, and the error labels
were never updated.
Something like:
Fixes: 5ec55823438e ("net: stmmac: add clocks management for gmac driver")
would let stable tell which kernels need this. It would usually be
targeted at the net tree as well.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index f256244ce0d11..4ebf4b6253743 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -8407,6 +8407,8 @@ static int __stmmac_dvr_probe(struct device *device,
> error_pcs_setup:
> stmmac_mdio_unregister(ndev);
> error_mdio_register:
> + pm_runtime_disable(device);
> + pm_runtime_put_noidle(device);
[Severity: High]
Is this pm_runtime_disable() balanced on PCI based stmmac devices?
The probe path only enables runtime PM when it is not already enabled:
pm_runtime_get_noresume(device);
pm_runtime_set_active(device);
if (!pm_runtime_enabled(device))
pm_runtime_enable(device);
Commit d90d0c175cf2 ("net: stmmac: Fix "Unbalanced pm_runtime_enable!"
warning") made that check conditional. The PCI core has already enabled
runtime PM before any driver binds:
drivers/pci/bus.c:pci_bus_add_device() {
...
pm_runtime_enable(&dev->dev);
...
}
So for the PCI glue drivers (stmmac_pci.c, dwmac-intel.c,
dwmac-loongson.c, dwmac-motorcomm.c), probe skips the enable. This
error path still disables, though. That removes the PCI core's enable
and leaves disable_depth at 1.
Every failure from stmmac_mdio_register() onward ends up here. That
includes -EPROBE_DEFER, and also failures from stmmac_pcs_setup(),
stmmac_phylink_setup(), stmmac_register_devlink() and
register_netdev(). After that:
local_pci_probe()
pm_runtime_put_sync(dev); <- no effect, runtime PM disabled
really_probe()
device_unbind_cleanup()
pm_runtime_reinit()
pm_runtime_set_suspended(dev);
pm_runtime_reinit() finds runtime PM disabled and the status
RPM_ACTIVE. The function is still in D0, but it is recorded as
RPM_SUSPENDED, and the parent bridge's child_count is decremented.
When stmmac itself retries a deferred probe, it re-enables runtime PM.
If the failure is permanent, or a different driver binds next (for
example vfio-pci through driver_override), runtime PM stays disabled
and the device still never runtime-suspends. The PCI callers'
error paths, such as intel_eth_pci_probe(), do not restore it.
Isn't that the same symptom the commit message says this fixes?
Could a local bool record whether this probe actually called
pm_runtime_enable(), so pm_runtime_disable() is only called in that
case?
stmmac_dvr_remove(), which the commit message names as the model,
already has the same unconditional pm_runtime_disable(). It looks like
it has the same mismatch on PCI. Later patches in the series do not
appear to change this error path.
> stmmac_napi_del(ndev);
> error_hw_init:
> destroy_workqueue(priv->wq);
[Severity: Medium]
This issue is pre-existing and was not introduced by this patch, and it
is separate from the runtime PM problem. Since this error path is being
matched against stmmac_dvr_remove(), should it also put the resets
back?
Before stmmac_hw_init(), __stmmac_dvr_probe() does:
if (priv->plat->stmmac_rst) {
ret = reset_control_assert(priv->plat->stmmac_rst);
reset_control_deassert(priv->plat->stmmac_rst);
...
}
ret = reset_control_deassert(priv->plat->stmmac_ahb_rst);
stmmac_dvr_remove() asserts both again:
if (priv->plat->stmmac_rst)
reset_control_assert(priv->plat->stmmac_rst);
reset_control_assert(priv->plat->stmmac_ahb_rst);
None of the probe error labels do this. After a failed or deferred
probe, the MAC is left out of reset.
stmmac_ahb_rst comes from devm_reset_control_get_optional_shared() in
stmmac_probe_config_dt(), and devres releases the handle without
asserting it. Could that leave the shared deassert_count raised? If
so, another consumer sharing the AHB reset could no longer really
assert it.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sun8i-emac-mux-uaf-v4-0-57eba8915f25%40gmail.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
2026-11-22 17:05 ` Maxime Chevallier
2026-11-22 17:35 ` Maxime Chevallier
@ 2026-11-24 11:16 ` netdev-bot+sashiko
2 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 11:16 UTC (permalink / raw)
To: aiyengar1990
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
p.zabel, linux, netdev, linux-arm-kernel, linux-sunxi,
linux-stm32, linux-kernel
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
2026-11-22 17:35 ` Maxime Chevallier
@ 2026-11-24 11:16 ` netdev-bot+sashiko
1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 11:16 UTC (permalink / raw)
To: aiyengar1990
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, wens, jernej.skrabec, samuel,
p.zabel, linux, netdev, linux-arm-kernel, linux-sunxi,
linux-stm32, linux-kernel
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@gmail.com>
[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
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-11-24 12:00 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 10:45 [PATCH net-next v4 0/5] net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering Arun Iyengar via B4 Relay
2026-11-20 10:45 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: Put the EPHY clock and reset after the MAC Arun Iyengar via B4 Relay
2026-11-22 16:47 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: Get the EPHY clock and reset before the MAC probe Arun Iyengar via B4 Relay
2026-11-22 16:51 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 3/5] net: stmmac: Balance runtime PM when the probe fails Arun Iyengar via B4 Relay
2026-11-22 17:03 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 4/5] net: stmmac: Add MDIO init and exit platform hooks Arun Iyengar via B4 Relay
2026-11-22 17:05 ` Maxime Chevallier
2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
2026-11-20 10:45 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: Register the MDIO mux in the MDIO setup Arun Iyengar via B4 Relay
2026-11-22 17:35 ` Maxime Chevallier
2026-11-24 11:16 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox