net: ethernet: sunplus: spl2sw: fix of_node refcount leaks
Subsystems (3)
v2 cover net: ethernet: sunplus: spl2sw: fix of_node refcount leaks
This series fixes of_node refcount leaks in the Sunplus SP7021 ethernet driver, found by inspection. Compile-tested only; no SP7021 hardware available here.
Patch 1/2 fixes the phy_node leak in the remove path. Patch 2/2 fixes multiple leaks in the probe path and depends on the cleanup contract from patch 1/2.
Changes since v1:
- Combined the two related fixes into a single series with cover letter, per netdev convention.
- Added "Compile-tested only" note to both commit messages (Andrew Lunn).
- Dropped Cc: [email protected] -- the leaks only manifest on driver unbind/rebind, which is not a path normally exercised on this SoC (Andrew Lunn).
- Fix author email to match Signed-off-by (DCO).
v1: https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
Shitalkumar Gandhi (2):
net: ethernet: sunplus: spl2sw: fix phy_node refcount leak in remove
net: ethernet: sunplus: spl2sw: fix multiple of_node refcount leaks in
probe
drivers/net/ethernet/sunplus/spl2sw_driver.c | 20 +++++++++++++------- drivers/net/ethernet/sunplus/spl2sw_phy.c | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 net: ethernet: sunplus: spl2sw: fix phy_node refcount leak in remove
mac->phy_node is acquired via of_parse_phandle() in spl2sw_probe() and stored in the mac private data, transferring ownership of the device_node reference to mac. On driver removal, spl2sw_phy_remove() disconnects the PHY but never drops that reference, so each probe-then-remove cycle leaks one of_node refcount per port permanently.
Drop the reference after phy_disconnect(). While at it, remove the redundant inner "if (ndev)" check; comm->ndev[i] was just verified non-NULL on the line above.
Compile-tested only; no SP7021 hardware available.
--- drivers/net/ethernet/sunplus/spl2sw_phy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/sunplus/spl2sw_phy.c +4 -2
@@ -79,12 +79,14 @@ int spl2sw_phy_connect(struct spl2sw_common *comm)void spl2sw_phy_remove (struct spl2sw_common *comm) {struct net_device *ndev; +struct spl2sw_mac *mac;int i;for (i =0 ; i <MAX_NETDEV_NUM ; i++)if (comm->ndev[i]) { ndev = comm->ndev[i]; -if (ndev) -phy_disconnect (ndev->phydev); + mac =netdev_priv (ndev); +phy_disconnect (ndev->phydev); +of_node_put (mac->phy_node); } }
Signature · 1 line
2.25.1
PATCH v2 2/2 net: ethernet: sunplus: spl2sw: fix multiple of_node refcount leaks in probe
In reply to Shitalkumar Gandhispl2sw_probe() acquires three of_node references that are never properly released in all paths:
- eth_ports_np from of_get_child_by_name() leaks on every probe.
- port_np returned from spl2sw_get_eth_child_node() (which exits a for_each_child_of_node() loop mid-iteration) leaks per loop pass.
- phy_np from of_parse_phandle() leaks on the -EPROBE_DEFER and spl2sw_init_netdev() failure goto paths, and the registered netdev's mac->phy_node is not released on the out_unregister_dev cleanup path.
Convert eth_ports_np and port_np to scoped __free(device_node), add explicit of_node_put(phy_np) on the two early-error gotos where ownership has not yet been transferred to mac->phy_node, and release each registered ndev's mac->phy_node in the out_unregister_dev loop before unregister_netdev().
The mac->phy_node release in the normal driver-remove path is handled by patch 1/2.
Compile-tested only; no SP7021 hardware available.
--- drivers/net/ethernet/sunplus/spl2sw_driver.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/ethernet/sunplus/spl2sw_driver.c +13 -7
@@ -319,10 +319,8 @@ static struct device_node *spl2sw_get_eth_child_node(struct device_node *ether_nstatic int spl2sw_probe (struct platform_device *pdev) { -struct device_node *eth_ports_np; -struct device_node *port_np; + struct device_node *eth_ports_np __free(device_node) = NULL;struct spl2sw_common *comm; -struct device_node *phy_np;phy_interface_t phy_mode;struct net_device *ndev;struct spl2sw_mac *mac;
@@ -418,8 +416,10 @@ static int spl2sw_probe(struct platform_device *pdev) }for (i =0 ; i <MAX_NETDEV_NUM ; i++) { -/* Get port@i of node ethernet-ports. */ - port_np =spl2sw_get_eth_child_node (eth_ports_np, i); + struct device_node *port_np __free(device_node) = +spl2sw_get_eth_child_node (eth_ports_np, i); +struct device_node *phy_np; +if (!port_np)continue ;
@@ -441,6 +441,7 @@ static int spl2sw_probe(struct platform_device *pdev)/* Get mac-address from nvmem. */ ret =spl2sw_nvmem_get_mac_address (&pdev->dev, port_np, mac_addr);if (ret == -EPROBE_DEFER ) { +of_node_put (phy_np); goto out_unregister_dev; }else if (ret) {dev_info (&pdev->dev,"Generate a random mac address!\n" );
@@ -449,8 +450,10 @@ static int spl2sw_probe(struct platform_device *pdev)/* Initialize the net device. */ ret =spl2sw_init_netdev (pdev, mac_addr, &ndev); -if (ret) +if (ret) { +of_node_put (phy_np); goto out_unregister_dev; + } ndev->irq = irq; comm->ndev[i] = ndev;
@@ -500,8 +503,11 @@ static int spl2sw_probe(struct platform_device *pdev) out_unregister_dev:for (i =0 ; i <MAX_NETDEV_NUM ; i++) -if (comm->ndev[i]) +if (comm->ndev[i]) { + mac =netdev_priv (comm->ndev[i]); +of_node_put (mac->phy_node);unregister_netdev (comm->ndev[i]); + } out_free_mdio:spl2sw_mdio_remove (comm);
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net v2 2/2] net: ethernet: sunplus: spl2sw: fix multiple of_node refcount leaks in probe
drivers/net/ethernet/sunplus/spl2sw_driver.c static struct device_node *spl2sw_get_eth_child_node(struct device_node *ether_n · line 322
Quoted 1 line · On Tue, 16 Jun 2026 01:20:32 +0530 Shitalkumar Gandhi wrote:
drivers/net/ethernet/sunplus/spl2sw_driver.c +1
-0+ struct device_node *eth_ports_np __free(device_node) = NULL;
Please don't use __free() in networking code
Signature · 1 line
pw-bot: cr
Jakub Kicinski
maintainerQuoted 7 lines · On Tue, 16 Jun 2026 01:20:30 +0530 Shitalkumar Gandhi wrote:
This series fixes
of_noderefcount leaks in the Sunplus SP7021 ethernet driver, found by inspection. Compile-tested only; no SP7021 hardware available here.Patch 1/2 fixes the
phy_nodeleak in the remove path. Patch 2/2 fixes multiple leaks in the probe path and depends on the cleanup contract from patch 1/2.
Wells Lu, please review.
Signature · 1 line
mping: SUNPLUS ETHERNET DRIVER
Hi Jakub,
I'm sorry that I can't test the fix.
I've left from Suplus and don't have the relevant hardware.
Best regards,
Wells Lu
Jakub Kicinski <[email protected]> 於 2026年6月19日週五 上午8:56寫道:
Quoted 13 lines · On Tue, 16 Jun 2026 01:20:30 +0530 Shitalkumar Gandhi wrote:
Quoted 7 lines
This series fixes
of_noderefcount leaks in the Sunplus SP7021 ethernet driver, found by inspection. Compile-tested only; no SP7021 hardware available here.Patch 1/2 fixes the
phy_nodeleak in the remove path. Patch 2/2 fixes multiple leaks in the probe path and depends on the cleanup contract from patch 1/2.Wells Lu, please review.
--
mping: SUNPLUS ETHERNET DRIVER
Jakub Kicinski
maintainerQuoted 2 lines · On Sun, 21 Jun 2026 12:38:06 +0800 呂芳騰 wrote:
I'm sorry that I can't test the fix.
I've left from Suplus and don't have the relevant hardware.
That makes things harder.. but you don't necessarily need HW to review most of the patches. If you don't intend to serve as a maintainer of the sunplus driver please sense a patch to MAINTAINERS and step down. Right now you are listed but don't seem to be fulfilling the duties. Or please review the patches to the best of your ability without testing.
Hi Jakub,
You are right. I will submit a patch to mark the SUNPLUS ETHERNET DRIVER as Orphaned, as I no longer have the hardware or the capacity to maintain it.
I contacted the managers at Sunplus, but they have declined to take over the maintenance position.
Thank you for your understanding, and sorry for any inconvenience caused.
Best regards,
Wells Lu
Jakub Kicinski <[email protected]> 於 2026年6月22日週一 上午4:22寫道:
Quoted 11 lines · On Sun, 21 Jun 2026 12:38:06 +0800 呂芳騰 wrote:
Quoted 2 lines
I'm sorry that I can't test the fix.
I've left from Suplus and don't have the relevant hardware.That makes things harder.. but you don't necessarily need HW to review most of the patches. If you don't intend to serve as a maintainer of the sunplus driver please sense a patch to
MAINTAINERSand step down. Right now you are listed but don't seem to be fulfilling the duties. Or please review the patches to the best of your ability without testing.