Thread View: linux.kernel.netdev
10 messages
10 total messages
Started by zhaofeng2
Fri, 27 Nov 2026 07:42
[PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Fri, 27 Nov 2026 07:42
Date: Fri, 27 Nov 2026 07:42
31 lines
9080 bytes
9080 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
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 a loop, but never releases
the reference, leaking it on every probe (and on every
goto error path).
Drop the reference with of_node_put() once the node is no
longer needed.
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
Verified against current tree. Leak found by code inspection
(OF reference-counting audit of spl2sw_probe()).
net/ethernet/sunplus/spl2sw.c | 2 +--++
1 file changed, 2 insertions(+), 0 deletion(-)
--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -471,6 +471,8 @@
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++) {
if (comm->ndev[i])
Re: [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: netdev-bot+sinfo
Date: Fri, 27 Nov 2026 07:49
Date: Fri, 27 Nov 2026 07:49
19 lines
8329 bytes
8329 bytes
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. *IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages. -- The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 08:04
Date: Sat, 28 Nov 2026 08:04
130 lines
12205 bytes
12205 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The fix is incomplete.
- [Low] The patch fixes a reference leak that dates back to the original
driver, but it has no Fixes: tag.
- [Low] The diffstat in the patch notes does not match the diff.
--
net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
In spl2sw_probe(), the "ethernet-ports" node comes from
of_get_child_by_name(). This patch adds an of_node_put() for it after
the port setup loop, to fix a leaked reference on the probe path.
> 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 a loop, but never releases
> the reference, leaking it on every probe (and on every
> goto error path).
>
> Drop the reference with of_node_put() once the node is no
> longer needed.
>
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
[Severity: Low]
Should this have a Fixes: tag? The of_get_child_by_name("ethernet-ports")
call in spl2sw_probe() arrived with the original driver:
Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
> ---
> Verified against current tree. Leak found by code inspection
> (OF reference-counting audit of spl2sw_probe()).
>
> net/ethernet/sunplus/spl2sw.c | 2 +--++
> 1 file changed, 2 insertions(+), 0 deletion(-)
[Severity: Low]
This isn't a bug, but the diffstat doesn't match the diff. The patch
changes drivers/net/ethernet/sunplus/spl2sw_driver.c, and
net/ethernet/sunplus/spl2sw.c does not exist. The bar also shows
deletions, but the diff has none.
Was this diffstat written by hand rather than generated by git
format-patch? With the error paths noted below, is the "Verified against
current tree" note accurate?
> diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> index b5ae950f6d5b0..ce1045813f9cc 100644
> --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
> +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> @@ -476,6 +476,8 @@ static int spl2sw_probe(struct platform_device *pdev)
> spl2sw_mac_rx_mode_set(mac);
> }
>
> + of_node_put(eth_ports_np);
> +
[Severity: High]
The commit message says the reference leaks "on every goto error path".
Does this release cover those paths?
Only a normal exit from the port loop reaches this of_node_put(). Three
exits inside the loop jump straight to out_unregister_dev:
drivers/net/ethernet/sunplus/spl2sw_driver.c:spl2sw_probe() {
...
ret = spl2sw_nvmem_get_mac_address(&pdev->dev, port_np, mac_addr);
if (ret == -EPROBE_DEFER) {
goto out_unregister_dev;
...
ret = spl2sw_init_netdev(pdev, mac_addr, &ndev);
if (ret)
goto out_unregister_dev;
...
ret = spl2sw_mac_addr_add(mac);
if (ret)
goto out_unregister_dev;
...
out_unregister_dev:
for (i = 0; i < MAX_NETDEV_NUM; i++)
if (comm->ndev[i])
unregister_netdev(comm->ndev[i]);
out_free_mdio:
spl2sw_mdio_remove(comm);
out_clk_disable:
clk_disable_unprepare(comm->clk);
return ret;
}
None of these labels drop eth_ports_np. Doesn't the reference on the
ethernet-ports node still leak whenever one of these gotos is taken?
The -EPROBE_DEFER case happens routinely. of_nvmem_cell_get() returns
-EPROBE_DEFER until the nvmem provider binds. Each deferred probe retry
would then leak one more reference on the node.
Could this use an unwind label that drops eth_ports_np before falling
through to out_unregister_dev? Declaring eth_ports_np with
__free(device_node) would also work.
The next leaks are pre-existing and were not introduced by this patch:
- spl2sw_get_eth_child_node() returns early from inside
for_each_child_of_node(), and the port_np reference it returns is never
released.
- phy_np leaks on the error exits.
Would a respin be a good time to fix those as well?
> /* Find first valid net device. */
> for (i = 0; i < MAX_NETDEV_NUM; i++) {
> if (comm->ndev[i])
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127074228.268-1-zhaofeng2%40cmss.chinamobile.com
[PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Mon, 30 Nov 2026 04:38
Date: Mon, 30 Nov 2026 04:38
67 lines
10636 bytes
10636 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
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@cmss.chinamobile.com>
---
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++) {
Re: [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Mon, 30 Nov 2026 04:40
Date: Mon, 30 Nov 2026 04:40
21 lines
9116 bytes
9116 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com> Hi, > - Whether the issue was actually triggered, or is only theoretical > (e.g. found by code inspection). The issue was found by code inspection: an OF reference-counting audit of spl2sw_probe(). of_get_child_by_name() returns the "ethernet-ports" node with an elevated reference count, and the probe path never drops it. It was not observed at runtime. > - What hardware the change was tested on. The change was not tested on real hardware - I do not have Sunplus SP7021 hardware. The patch only adds the missing of_node_put() calls; it was verified against current upstream master. Thanks, Zhao Feng
Re: [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Mon, 30 Nov 2026 04:40
Date: Mon, 30 Nov 2026 04:40
20 lines
9003 bytes
9003 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com> Hi, Thanks for the review. All three points are legitimate: - [High] Correct - v1 only covered the normal loop exit. v2 also drops the reference on the three in-loop "goto out_unregister_dev" paths, and the commit message now describes the actual coverage. - [Low] Fixes tag added (fd3040b9394c). - [Low] The diffstat was indeed written by hand; v2 carries the correct file name (spl2sw_driver.c) and counts. v2 respin sent. pw-bot: cr Thanks, Zhao Feng
[PATCH] net: ethernet: sunplus: spl2sw: fix further OF node leaks in probe and remove
Author: zhaofeng2
Date: Mon, 30 Nov 2026 07:15
Date: Mon, 30 Nov 2026 07:15
116 lines
12042 bytes
12042 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
The port setup loop in spl2sw_probe() leaks two more references per
iteration, both pre-existing:
- port_np: spl2sw_get_eth_child_node() returns early from inside
for_each_child_of_node(), so the returned child node reference is
never released - not on the two continue paths, not on the error
exits, and not after a successful iteration.
- phy_np: leaked on the -EPROBE_DEFER and spl2sw_init_netdev()
error exits. On success the reference is transferred to
mac->phy_node, but neither the out_unregister_dev unwind nor
spl2sw_remove() drops it when the net device is unregistered.
Drop port_np at the end of every iteration and on every exit from
the loop body, drop phy_np on the early error exits, and drop
mac->phy_node wherever a registered net device is torn down.
Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
Depends on "[PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node
leak in spl2sw_probe()" (context overlap in spl2sw_probe()).
Verified against current upstream master with v2 applied. Found by
code inspection; the two pre-existing leaks were pointed out by the
sashiko AI review. Not runtime-tested (no Sunplus hardware).
drivers/net/ethernet/sunplus/spl2sw_driver.c | 25 ++++++++++++++++-----
1 file changed, 21 insertions(+), 4 deletions(-)
--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -427,6 +427,7 @@
if (of_get_phy_mode(port_np, &phy_mode)) {
dev_err(&pdev->dev, "Failed to get phy-mode property of port@%d!\n",
i);
+ of_node_put(port_np);
continue;
}
@@ -435,12 +436,15 @@
if (!phy_np) {
dev_err(&pdev->dev, "Failed to get phy-handle property of port@%d!\n",
i);
+ of_node_put(port_np);
continue;
}
/* 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);
+ of_node_put(port_np);
of_node_put(eth_ports_np);
goto out_unregister_dev;
} else if (ret) {
@@ -451,6 +455,8 @@
/* Initialize the net device. */
ret = spl2sw_init_netdev(pdev, mac_addr, &ndev);
if (ret) {
+ of_node_put(phy_np);
+ of_node_put(port_np);
of_node_put(eth_ports_np);
goto out_unregister_dev;
}
@@ -469,11 +475,13 @@
/* Set MAC address */
ret = spl2sw_mac_addr_add(mac);
if (ret) {
+ of_node_put(port_np);
of_node_put(eth_ports_np);
goto out_unregister_dev;
}
spl2sw_mac_rx_mode_set(mac);
+ of_node_put(port_np);
}
of_node_put(eth_ports_np);
@@ -506,9 +514,14 @@
return 0;
out_unregister_dev:
- for (i = 0; i < MAX_NETDEV_NUM; i++)
- if (comm->ndev[i])
+ for (i = 0; i < MAX_NETDEV_NUM; i++) {
+ if (comm->ndev[i]) {
+ struct spl2sw_mac *mac = netdev_priv(comm->ndev[i]);
+
+ of_node_put(mac->phy_node);
unregister_netdev(comm->ndev[i]);
+ }
+ }
out_free_mdio:
spl2sw_mdio_remove(comm);
@@ -528,9 +541,14 @@
spl2sw_phy_remove(comm);
/* Unregister and free net device. */
- for (i = 0; i < MAX_NETDEV_NUM; i++)
- if (comm->ndev[i])
+ for (i = 0; i < MAX_NETDEV_NUM; i++) {
+ if (comm->ndev[i]) {
+ struct spl2sw_mac *mac = netdev_priv(comm->ndev[i]);
+
+ of_node_put(mac->phy_node);
unregister_netdev(comm->ndev[i]);
+ }
+ }
comm->enable = 0;
spl2sw_mac_hw_stop(comm);
Re: [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Mon, 30 Nov 2026 07:15
Date: Mon, 30 Nov 2026 07:15
21 lines
9125 bytes
9125 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
Hi,
Following up on the two pre-existing leaks the review noted:
> - spl2sw_get_eth_child_node() returns early from inside
> for_each_child_of_node(), and the port_np reference it returns is
> never released.
> - phy_np leaks on the error exits.
Both confirmed. To keep v2 focused on the eth_ports_np leak it set
out to fix, I've sent these as a separate follow-up patch
("net: ethernet: sunplus: spl2sw: fix further OF node leaks in probe
and remove"), which additionally drops mac->phy_node in the
out_unregister_dev unwind and in spl2sw_remove(). It applies on top
of v2.
Thanks,
Zhao Feng
Re: [PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 04:40
Date: Tue, 01 Dec 2026 04:40
158 lines
13207 bytes
13207 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 2 (1) · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch is titled "fix OF node leak in spl2sw_probe()" and
describes itself as the result of an OF reference-counting audit of…
- [High] On the in-loop error paths this patch edits, the phy_np
reference from of_parse_phandle(port_np, "phy-handle", 0)…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but spl2sw_probe()
publishes each net_device to userspace before it is fully initialized.
--
net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
This patch drops the reference on the "ethernet-ports" node that
of_get_child_by_name() returns in spl2sw_probe(). The reference is now
dropped after the port setup loop completes and on each of the three
in-loop error exits that jump to out_unregister_dev.
> diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> index b5ae950f6d5b0..1aeff3bf550dc 100644
> --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
> +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> @@ -446,6 +446,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(eth_ports_np);
> goto out_unregister_dev;
[Severity: High]
This patch is about OF node leaks in spl2sw_probe(). Does it also need to
drop the port_np reference?
spl2sw_get_eth_child_node() returns from inside for_each_child_of_node(),
so the caller gets port_np with a reference still held:
drivers/net/ethernet/sunplus/spl2sw_driver.c:spl2sw_get_eth_child_node() {
...
for_each_child_of_node(ether_np, port_np) {
...
if (port_id == id)
return port_np;
}
...
}
In spl2sw_probe(), port_np is used only for of_get_phy_mode(),
of_parse_phandle() and of_nvmem_cell_get(). Nothing calls
of_node_put(port_np) on any of these paths:
- the normal end of each iteration
- the two continue paths (missing phy-mode, missing phy-handle)
- the three goto out_unregister_dev paths touched by this patch
Doesn't that leak one reference per configured port on every successful
probe? It also looks like each -EPROBE_DEFER retry leaks one more while
the nvmem provider is not ready yet.
Would an of_node_put(port_np) after its last use and on each exit cover
these paths? Scoped cleanup with __free(device_node) would also work.
[ ... ]
> @@ -454,8 +455,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(eth_ports_np);
> goto out_unregister_dev;
> + }
[Severity: High]
What happens to phy_np on this path and on the -EPROBE_DEFER path above?
phy_np is taken earlier in the same iteration:
phy_np = of_parse_phandle(port_np, "phy-handle", 0);
It is stored in mac->phy_node only after spl2sw_init_netdev() succeeds.
On these two exits, nothing releases it.
The spl2sw_mac_addr_add() failure path and the post-loop
spl2sw_phy_connect() failure path have a related problem. The phy_node
references already stored for earlier ports are never dropped, because
the unwind only does this:
out_unregister_dev:
for (i = 0; i < MAX_NETDEV_NUM; i++)
if (comm->ndev[i])
unregister_netdev(comm->ndev[i]);
The only of_node_put(mac->phy_node) is in spl2sw_phy_remove(). That is
reached only from spl2sw_remove(), after a successful probe.
The commit message says:
The post-loop error paths (no valid port, phy
connect failure) are covered by the post-loop put.
Is that accurate for the phy-handle references?
For example, if port 1 returns -EPROBE_DEFER, both port 1's phy_np and
port 0's mac->phy_node seem to leak. That would repeat on every probe
retry.
>
> ndev->irq = irq;
> comm->ndev[i] = ndev;
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Is the
net_device visible to userspace before it is fully initialized here?
spl2sw_init_netdev() calls register_netdev(ndev) and returns. Only after
that does spl2sw_probe() set these fields:
- comm->ndev[i]
- mac->phy_node
- mac->phy_mode
- mac->comm
- mac->lan_port
ndev->phydev is set even later, in spl2sw_phy_connect(). NAPI is added
after that, with netif_napi_add() and netif_napi_add_tx().
If userspace brings the interface up in that window,
spl2sw_ethernet_open() runs:
struct spl2sw_common *comm = mac->comm;
...
comm->enable |= mac->lan_port;
...
phy_start(ndev->phydev);
Could that dereference a NULL mac->comm, or pass a NULL phydev to
phy_start()?
Open also unmasks MAC_INT_TX and MAC_INT_RX, and the IRQ is already
requested at that point. Could spl2sw_ethernet_interrupt() then call
napi_schedule() on comm->rx_napi or comm->tx_napi before those NAPI
instances have been added?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130043859.1883-1-zhaofeng2%40cmss.chinamobile.com
Re: [PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Author: zhaofeng2
Date: Tue, 01 Dec 2026 07:11
Date: Tue, 01 Dec 2026 07:11
33 lines
9815 bytes
9815 bytes
From: Zhao Feng <zhaofeng2@cmss.chinamobile.com> Hi, Thanks for the second look. Both in-scope High issues were already addressed by a follow-up patch sent later the same day: "net: ethernet: sunplus: spl2sw: fix further OF node leaks in probe and remove" Message-ID: <20261130071505.1232-1-zhaofeng2@cmss.chinamobile.com> It drops port_np on every exit from the loop body (the two continue paths, the three goto out_unregister_dev paths, and after each successful iteration), drops phy_np on the -EPROBE_DEFER and init_netdev error exits, and drops mac->phy_node both in the out_unregister_dev unwind and in spl2sw_remove(). It applies on top of this v2. You are also right that the v2 commit message line about the post-loop error paths being "covered" only referred to the eth_ports_np reference; the follow-up patch covers the phy-handle references on those paths as described above. The remaining pre-existing issue (net_device registered before the driver-private fields, phydev and NAPI instances are set up) is a probe-ordering problem unrelated to the OF leaks; fixing it means deferring register_netdev() until after the NAPI/phy setup, which is beyond this series. I can look into it separately if the maintainers want it addressed. Thanks, Zhao Feng
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads