* [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-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, 1 reply; 10+ 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] 10+ 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
0 siblings, 0 replies; 10+ 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] 10+ 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-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, 1 reply; 10+ 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] 10+ 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
0 siblings, 0 replies; 10+ 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] 10+ 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-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, 1 reply; 10+ 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] 10+ 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
0 siblings, 0 replies; 10+ 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] 10+ 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
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, 1 reply; 10+ 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] 10+ 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
0 siblings, 0 replies; 10+ 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] 10+ 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
4 siblings, 0 replies; 10+ 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] 10+ messages in thread