From: netdev-bot+sashiko@kernel.org
To: zhaofeng2@cmss.chinamobile.com
Cc: wells.lu@sunplus.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe()
Date: Tue, 01 Dec 2026 04:40:16 +0000 [thread overview]
Message-ID: <179610001649.3146.6303117369174207988@kernel.org> (raw)
In-Reply-To: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com>
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
next prev parent reply other threads:[~2026-12-01 4:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:42 [PATCH] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe() zhaofeng2
2026-11-27 7:49 ` netdev-bot+sinfo
2026-11-30 4:40 ` zhaofeng2
2026-11-28 8:04 ` netdev-bot+sashiko
2026-11-30 4:40 ` zhaofeng2
2026-11-30 7:15 ` zhaofeng2
2026-11-30 4:38 ` [PATCH v2] " zhaofeng2
2026-12-01 4:40 ` netdev-bot+sashiko [this message]
2026-11-30 7:15 ` [PATCH] net: ethernet: sunplus: spl2sw: fix further OF node leaks in probe and remove zhaofeng2
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179610001649.3146.6303117369174207988@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=wells.lu@sunplus.com \
--cc=zhaofeng2@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox