From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBB2D1F008A0; Tue, 1 Dec 2026 04:40:16 +0000 (UTC) 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== Subject: Re: [PATCH v2] net: ethernet: sunplus: spl2sw: fix OF node leak in spl2sw_probe() 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 Date: Tue, 01 Dec 2026 04:40:16 +0000 Message-ID: <179610001649.3146.6303117369174207988@kernel.org> In-Reply-To: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com> References: <20261130043859.1883-1-zhaofeng2@cmss.chinamobile.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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