[net-next,v4,3/5] net: stmmac: Balance runtime PM when the probe fails

Message ID 20261120-sun8i-emac-mux-uaf-v4-3-57eba8915f25@gmail.com (mailing list archive)
State New
Headers
Series net: stmmac: dwmac-sun8i: Fix the EPHY and MDIO mux ordering |

Commit Message

Arun Iyengar via B4 Relay Nov. 20, 2026, 10:45 a.m. UTC
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(+)
  

Comments

sashiko-bot@kernel.org Nov. 21, 2026, 10:46 a.m. UTC | #1
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: stmmac: unbalanced pm_runtime_disable() in
  __stmmac_dvr_probe()
- [Low] net: stmmac: missing Fixes trailer for probe runtime PM leak
--

commit 150d8ab7f1c2f574c3442bec9dafca1bba988cdd
Author: Arun Iyengar <aiyengar1990@gmail.com>

> net: stmmac: Balance runtime PM when the probe fails
>
> __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>

[Severity: Low]
Should this bug fix include a Fixes tag for the commit that added runtime
PM handling to probe without cleaning it up on the error path?

  Fixes: 5ec55823438e ("net: stmmac: add clocks management for gmac driver")

> 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);
>  	stmmac_napi_del(ndev);
>  error_hw_init:
>  	destroy_workqueue(priv->wq);

[Severity: Medium]
Can calling pm_runtime_disable(device) unconditionally here leave runtime
PM unbalanced on buses that enable runtime PM before probing?

Earlier in __stmmac_dvr_probe(), pm_runtime_enable() is only called when
runtime PM is not already enabled:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:__stmmac_dvr_probe() {
    ...
	pm_runtime_get_noresume(device);
	pm_runtime_set_active(device);
	if (!pm_runtime_enabled(device))
		pm_runtime_enable(device);
    ...
}

For PCI stmmac devices, pci_bus_add_device() enables runtime PM before the
driver probes, so __stmmac_dvr_probe() skips pm_runtime_enable().  If
stmmac_mdio_register() or a later step fails or defers, this error path
still calls pm_runtime_disable(device), incrementing disable_depth from 0
to 1.  When probe unwind runs pm_runtime_reinit(), it sees runtime PM
disabled and forces the device to RPM_SUSPENDED while still in D0,
decrementing the parent bridge's active child count and causing a
subsequent re-probe's pm_runtime_get_sync() in local_pci_probe() to fail
with -EACCES.
  
Maxime Chevallier Nov. 22, 2026, 5:03 p.m. UTC | #2
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
  

Patch

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