[PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy()
From: Selby Mashiki
Date: Sun Oct 25 2026 - 16:33:32 EST
In bgx_init_of_phy(), device_for_each_child_node(&bgx->pdev->dev, fwn)
breaks out of the loop without calling fwnode_handle_put(fwn) if
to_of_node(fwn) returns NULL.
Switch the loop to device_for_each_child_node_scoped() and remove the
manual of_node_put(node) calls so the child fwnode_handle reference is
automatically released on all loop exit paths.
Fixes: 9d28f9491258 ("net: thunder_bgx: add a missing of_node_put")
Signed-off-by: Selby Mashiki <mashikiselby@xxxxxxxxx>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index b63039999..3fe3f80db 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1467,11 +1467,10 @@ static int bgx_init_acpi_phy(struct bgx *bgx)
static int bgx_init_of_phy(struct bgx *bgx)
{
- struct fwnode_handle *fwn;
struct device_node *node = NULL;
u8 lmac = 0;
- device_for_each_child_node(&bgx->pdev->dev, fwn) {
+ device_for_each_child_node_scoped(&bgx->pdev->dev, fwn) {
struct phy_device *pd;
struct device_node *phy_np;
@@ -1506,10 +1505,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac++;
- if (lmac == bgx->max_lmac) {
- of_node_put(node);
+ if (lmac == bgx->max_lmac)
break;
- }
}
return 0;
@@ -1524,7 +1521,6 @@ static int bgx_init_of_phy(struct bgx *bgx)
bgx->lmac[lmac].phydev = NULL;
}
}
- of_node_put(node);
return -EPROBE_DEFER;
}
--
2.56.0