🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24970

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

#24970
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 04:40
158 lines
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
Technical Details
Message-ID: <179610001649.3146.6303117369174207988@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374703-linux-kernel-netdev=dewy.ru
References: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374703-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in
 spl2sw_probe()
Date: Tue, 01 Dec 2026 04:40:16 +0000
Organization: Usenet Network
Message-ID: <179610001649.3146.6303117369174207988@kernel.org>
References: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1615477"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:K09aAUnvFjIpVqu6ELe9Dj/i6AM= sha256:WwmeqLVkVTDXkj12ORjM4a6TtnOCJnzqbEpm2XKotYc=
	sha1:wrCsXocyfnWR3cqyfq1T43vHC3Q= sha256:yRcNwdB1YWk+XVpkhmzol5cMTBb2aGt55Sgjcmwhfas=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9565011723B; Tue,  1 Dec 2026 07:40:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 96SsLU_j2_Xg;
	Tue,  1 Dec 2026 07:40:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-374703-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id E8BF9117233; Tue,  1 Dec 2026 07:40:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id BB37C6019F9; Tue,  1 Dec 2026 04:40:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796100018;
	b=mmxpjTGWUShNHahGbQOCaPDW2k71aS7EbZbLh5NTFoKyPQPt7+2JYOUTfIpGpm34uyii
	 CcwVi6r8P+UTmK+ZmWEFPv6ZMcRKoyeIF3/dG14d9Ym6l0FtG2NACW1MxtrNr9KTPn8H6
	 8bw3qrMzlAOrn0nmz7OGnhtgPtoowDpnilKZlDnxZZD4eDdNc6d0RyN+2WcqRPhWOY60f
	 iw/uM/GwHwvU7WO1zTwRhkk6rutwJUkKaO20MMVuupKPDQ2iFqrCD+cfd0DBd48P8QgLA
	 eFYvOaNK6ESM5DRLAJ31Y+lch99RyVxnpNBbDmGYUe9HjjvXNEGtjonBN27TnldywMg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796100018;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=gRAA6O4CVE89XGs12IKZrAo26qv6Q7tMyduX9uhpHB8=;
	b=dpH79BdEit1no4T3XO3xE3SvpazoiBzhH+y2rD6jwk99tNIIRKG2EubPsvNQ2qyrj92S
	 aArXeuzOzsiZ2KkX1xftmkT0xc9to3ZCrbUmEshLmoOudDuqe3A7DQUcgSJ+icc8yASNi
	 GdTieYRRTjbx/LvsbgeW20T1m/v1B85lHHfAnfG+hkz43jbpC0AUQuQV6NUX2W4WtAhn2
	 pFKJS2rnMSdToBuWXZkB0LPTEpefu8+3AaCP3Cm/m4JSpcmvwteIzoB6FCyZAqVH+yVyt
	 Ukuh0dC+osXEum48LZQysO8GdPlPaqOdRDTDUWpfBaPFQEXJRQS0shd4msUI5b/+Gdg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jFEfEThl;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 948E9606A33A;
	Tue,  1 Dec 2026 04:40:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jFEfEThl
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796100017;
	b=qJd7MHYCQ9tSKzF8dFA1xT3rscPHh3keG2s5vKU5ouiIhNRWJahMVbuVh3pF8j223Hxu
	 Yu5Sw0hFEl5E911/Mq+1f5OnndA2Isb4hbGbPG9d5w6X9kl6fZJs4zOKP0MgTarVoYrD7
	 I2wwH110fS1HovoQsrI+14N+U/koo6yMmTK67Qqd3BcT2ZKA43NvJeOkptircL8166uYn
	 HyxOVp+mw+xRh775ks/K7lLN88fIJ40IsjFEdaF/W7tCocQNzrFu9sMoYLXnxxzz0NUo4
	 oND+C6d0VZYtmXp4A/lLAvyqWmTNvhTtW4L0nMvg1UADkByjFW2uFIweijmjBlHpvWw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796100017;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=gRAA6O4CVE89XGs12IKZrAo26qv6Q7tMyduX9uhpHB8=;
	b=r/krOG0vDZq481NZy3OOxfbENGGCdUNXX8sWnZx6XkaxRw4rU54NnyALj8QP/09WerF8
	 Q7OQJJAfHHbO0hHe4JcN9NOnwpcTIBJfj+totEKJycTX/12MLfD8UwNDdbSB1XQ/26OAL
	 7IzZR+koAgXK/wGlwN+4pnCksytQM0oyVP05PUlDhwQeKQqmGYZ+AlL7dWcmgQsO83Z08
	 RsfYn/1kcaISVmgqohsliq7ISPmvW6hRhR1YUBdmrGrd4wXsKgyzPo/uV0mQXdRqeaMS7
	 lqv0aD6WoIu5AB5viRenWs9WlnZE+/cYM/DLifbTeisHJTwcd5Bnn0f9YkKStxoi4Rg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jFEfEThl;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39FD606A320;
	Tue,  1 Dec 2026 04:40:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBB2D1F008A0;
	Tue,  1 Dec 2026 04:40:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796100017;
	bh=gRAA6O4CVE89XGs12IKZrAo26qv6Q7tMyduX9uhpHB8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=jFEfEThlytoo6PTD9jn1UIcW1JF3qq9dKaqFKTGsYhw9aU7T4Fo8/SgdawU7KEJb6
	 RERSuFGlQ33hzS2WstOhbTk+4t7ujzkLlCfvP6J524UAX21WKjXvoCkZrIhwY0gVEg
	 8ByvWAxz6F6CGdPnwLknxpVukStwN8qEMUuXJvzMzskakLZCu2gtaJh4tIDzGBctJJ
	 lRmQXpIl4TgHRbzpg9qtXxNyfJXOAkkbQUAjF4EXjnfJxSWMUPsPIpT9yiiTlKS7cu
	 KnWKRgNX/PUlAtgerp5z59JY16lD25GJPuRTqVQrqIjiqj1JAuP7oHW7CnUHXQ7NK3
	 OnxfP851uqoEQ==
X-Cc: wells.lu@sunplus.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
 kuba@kernel.org
X-In-Reply-To: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list