Skip to contentSkip to conversation

net: xgene: fix mdio_np leak in xgene_mdiobus_register()

PATCH Applied Shitalkumar Gandhi 3 participants 4 messages May 7 – May 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: xgene: fix mdio_np leak in xgene_mdiobus_register()

The for_each_child_of_node() loop captures mdio_np via break, holding the refcount. of_mdiobus_register() does not consume the reference, so it leaks on success.

Put it after registration.

Fixes e6ad767305eb ("drivers: net: Add APM X-Gene SoC ethernet driver support.")
---
 drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +3 -1
index b854b6b42d77..2926e1e59941 100644
@@ -910,7 +910,9 @@ static int xgene_mdiobus_register(struct xgene_enet_pdata *pdata,
 			return -ENXIO;
 		}
 
-		return of_mdiobus_register(mdio, mdio_np);
+		ret = of_mdiobus_register(mdio, mdio_np);
+		of_node_put(mdio_np);
+		return ret;
 	}
 
 	/* Mask out all PHYs from auto probing. */
Signature · 1 line
2.25.1
#1 lore raw
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 7 May 2026 19:50:24 +0530 you wrote:

The for_each_child_of_node() loop captures mdio_np via break, holding the refcount. of_mdiobus_register() does not consume the reference, so it leaks on success.

Put it after registration.

Fixes e6ad767305eb ("drivers: net: Add APM X-Gene SoC ethernet driver support.")

[...]

Here is the summary with links:
- [net] net: xgene: fix mdio_np leak in xgene_mdiobus_register()

    https://git.kernel.org/netdev/net/c/a450063ef86b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Shitalkumar Gandhi
Quoted 8 lines · Shitalkumar Gandhi

The for_each_child_of_node() loop captures mdio_np via break, holding the refcount. of_mdiobus_register() does not consume the reference, so it leaks on success.

Put it after registration.

Fixes e6ad767305eb ("drivers: net: Add APM X-Gene SoC ethernet driver support.")

FTR: There is an AI-generated review of this patch which you may
want to look at for possible follow-up. I do not believe it should block progress of this patch.

reviewer
#3 lore raw
Quoted 7 lines · Simon Horman
Quoted 6 lines · Shitalkumar Gandhi

The for_each_child_of_node() loop captures mdio_np via break, holding the refcount. of_mdiobus_register() does not consume the reference, so it leaks on success.

Put it after registration.

Quoted 8 lines
Quoted 2 lines
Fixes e6ad767305eb ("drivers: net: Add APM X-Gene SoC ethernet driver support.")

FTR: There is an AI-generated review of this patch which you may
want to look at for possible follow-up. I do not believe it should block progress of this patch.

I meant to mention that the AI-generated review I'm referring to is available on sashiko.dev.