[PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()

From: zhaofeng2

Date: Sun Nov 29 2026 - 23:39:12 EST


From: Zhao Feng <zhaofeng2@xxxxxxxxxxxxxxxxxxxx>

spl2sw_probe() calls of_get_child_by_name() to obtain the
"ethernet-ports" child node and uses it as the parent for
spl2sw_get_eth_child_node() in the port setup loop, but never
releases the reference: it leaks on every probe, on the three
in-loop "goto out_unregister_dev" paths, and would leak on the late
error paths after the loop.

Drop the reference right after the loop completes, and on each
in-loop error exit. The post-loop error paths (no valid port, phy
connect failure) are covered by the post-loop put.

Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Zhao Feng <zhaofeng2@xxxxxxxxxxxxxxxxxxxx>
---
v2: cover the in-loop error paths as well, not just the normal loop
exit (sashiko review); add the Fixes tag; fix the diffstat file
name (spl2sw_driver.c, not spl2sw.c).

Verified against current upstream master. Leak found by code
inspection (OF reference-counting audit of spl2sw_probe()). Not
runtime-tested (no Sunplus hardware).

drivers/net/ethernet/sunplus/spl2sw_driver.c | 11 ++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -441,6 +441,7 @@
/* Get mac-address from nvmem. */
ret = spl2sw_nvmem_get_mac_address(&pdev->dev, port_np, mac_addr);
if (ret == -EPROBE_DEFER) {
+ of_node_put(eth_ports_np);
goto out_unregister_dev;
} else if (ret) {
dev_info(&pdev->dev, "Generate a random mac address!\n");
@@ -449,8 +450,10 @@

/* Initialize the net device. */
ret = spl2sw_init_netdev(pdev, mac_addr, &ndev);
- if (ret)
+ if (ret) {
+ of_node_put(eth_ports_np);
goto out_unregister_dev;
+ }

ndev->irq = irq;
comm->ndev[i] = ndev;
@@ -465,11 +468,15 @@

/* Set MAC address */
ret = spl2sw_mac_addr_add(mac);
- if (ret)
+ if (ret) {
+ of_node_put(eth_ports_np);
goto out_unregister_dev;
+ }

spl2sw_mac_rx_mode_set(mac);
}
+
+ of_node_put(eth_ports_np);

/* Find first valid net device. */
for (i = 0; i < MAX_NETDEV_NUM; i++) {