🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13327

Re: [PATCH] net: ti: icssg-prueth: Fix device_node refcount leak in prueth_probe()

#13327
From: Simon Horman
Date: Mon, 09 Nov 2026 16:59
96 lines
11712 bytes
On Mon, Nov 09, 2026 at 04:52:35PM +0000, Simon Horman wrote:
> On Fri, Oct 30, 2026 at 04:56:51PM +0800, laixiangwu wrote:
> > prueth_probe() takes references on the eth0_node/eth1_node device nodes
> > with of_node_get() and stores them in prueth->eth_node[]. If either of
> > the "ti,mii-g-rt" or "ti,mii-rt" syscon regmap lookups fails, probe()
> > returns -ENODEV without dropping those references, leaking the device
> > nodes.
> > 
> > Jump to the existing put_cores label so the error path releases the
> > eth0_node/eth1_node references like all the other failure paths in the
> > function do.
> > 
> > Fixes: 128d5874c082 ("net: ti: icssg-prueth: Add ICSSG ethernet driver")
> > Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
> > ---
> >  drivers/net/ethernet/ti/icssg/icssg_prueth.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> > index 591be5c80..9b971d1df 100644
> > --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> > +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> > @@ -2258,13 +2258,15 @@ static int prueth_probe(struct platform_device *pdev)
> >  	prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt");
> >  	if (IS_ERR(prueth->miig_rt)) {
> >  		dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n");
> > -		return -ENODEV;
> > +		ret = -ENODEV;
> > +		goto put_cores;
> >  	}
> >  
> >  	prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt");
> >  	if (IS_ERR(prueth->mii_rt)) {
> >  		dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n");
> > -		return -ENODEV;
> > +		ret = -ENODEV;
> > +		goto put_cores;
> >  	}
> >  
> >  	prueth->pa_stats = syscon_regmap_lookup_by_phandle(np, "ti,pa-stats");
> 
> Hi Laixianwu,
> 
> Thanks, this patch looks correct to me.
> And I appreciate your feedback to the AI bots.
> 
> But I wonder if this nearby check also leaks a reference,
> because while it drops one, wouldn't there be two if the
> condition is met?
> 
>         if (eth0_node == eth1_node) {
>                 dev_err(dev, "port0 and port1 can't have same reg\n");
>                 of_node_put(eth0_node);
>                 return -ENODEV;
>         }

Sorry, one more thing. Which is not strictly related.  But as we're on the
topic of error paths in this function, I am not convinced of the validity
of the value of reg being used even when the call to of_property_read_u32
fails in this loop:

        for_each_child_of_node(eth_ports_node, eth_node) {
                u32 reg;

                if (strcmp(eth_node->name, "port"))
                        continue;
                ret = of_property_read_u32(eth_node, "reg", &reg);
                if (ret < 0) {
                        dev_err(dev, "%pOF error reading port_id %d\n",         
                                eth_node, ret);
                }

                of_node_get(eth_node);

                if (reg == 0) {
                        eth0_node = eth_node;
                        if (!of_device_is_available(eth0_node)) {
                                of_node_put(eth0_node);
                                eth0_node = NULL;
                        }
                } else if (reg == 1) {
                        eth1_node = eth_node;
                        if (!of_device_is_available(eth1_node)) {
                                of_node_put(eth1_node);
                                eth1_node = NULL;
                        }
                } else {
                        dev_err(dev, "port reg should be 0 or 1\n");
                }
        }

> 
> Also, for future reference, it would probably be better to put
> two similar fixes for related drivers in a two-patch patch-set,
> rather than posting them separately.
Technical Details
Message-ID: <20261109165902.GS18859@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359466-linux-kernel-netdev=dewy.ru
References: <20261030085651.1944-1-laixiangwu@cmss.chinamobile.com> <20261109165235.GR18859@horms.kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359466-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: ti: icssg-prueth: Fix device_node refcount leak in
 prueth_probe()
Date: Mon, 9 Nov 2026 16:59:02 +0000
Organization: Usenet Network
Message-ID: <20261109165902.GS18859@horms.kernel.org>
References: <20261030085651.1944-1-laixiangwu@cmss.chinamobile.com>
 <20261109165235.GR18859@horms.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="407320"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0JmZ8Qh88y/RjMeQTt5D/2FMi1c= sha256:NAnc6m23Qca4JmxlnKFYNKPxcFmHhPXKR8PsRu/G35A=
	sha1:BfHsZ0dlvVjle1k+d5xZEhmcyEE= sha256:mVFs8jBlYueNXZx0klEw85DZlUb7tHC61RNAWRf+JAw=
Content-Disposition: inline
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 F09851138A2; Mon,  9 Nov 2026 20:07:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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] 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 ydFWvz6JNVVH;
	Mon,  9 Nov 2026 20:07:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359466-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id B85D811384E; Mon,  9 Nov 2026 20:07:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id B9989470F0; Mon,  9 Nov 2026 17:00:10 +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=1794243563;
	b=Hv+ULF5TWpV0ha3qbVsuoYHRCkcKecQNrBYt0FiO1yG7cASG8PpmZGUGoxyQYS+MdEWc
	 alF4oBVXVLS4OVvv3XV92H/+iuxxMSz5EwWdCZ+/+7JYwEIojqBr+dAgwoEcm/U5k6W7y
	 N7aQda5FTjHz7943QhYe1b4uY9kf4mP43nRhNfdrzuSHI/j5PS4+4UcycsK719Vt5EH/P
	 rZ/03w7y+BIActrO4JKlSEkTVEJ7tncfwPHdOGT6JJ316obffl3eMecUmvRT3SDXetgD7
	 gklukHKSKEpr7srk+3gcZuoIeWLB1rYI4v/V0klWyS3jmd/fNbicqzVZr8MmsYtD4yA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794243563;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=0LtJx1KBdKZ3ZI9o+1o9OL4PdjTAWomKB8/BPDT/SD0=;
	b=oIfbP8SCwSdNn3o1M4I/vjFZSInmJM9bW0fZKnaEHtIEqpY/ktWqEsjqcJ3ojAly33Iv
	 IyTEDF0QgGuox/7KGZ3ovaHPy410xsJXCNM5MtftESQJ5QFt/xR+O5AkfXvSl2wQXFicj
	 0v8SJwuiIV7xnYQbgnXkKlE82NDula1BZlCb0lp217+Dp1PD39CNIqtyTbnq/PCI8yhKq
	 4y8HNJy2LeG8kJeBNcwDg7MiGp0noD1f22GMX1z8iQbx+2YzRqapuLGbiwOZ4zudNIKun
	 /65KnrvotaSvpms1lwuL9tboxwwprcoB7npBCPoqcYLYTHtZCZXIP8zHYFKv379seHw==
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=YkdDtHy+;
	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 D0A64606A413;
	Mon,  9 Nov 2026 16:59:23 +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=YkdDtHy+
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=1794243548;
	b=BBw6LX4CjRkXqVvTsjqZZsN3yWww2AtKy6LWrF2auiCPTcvl+u3GNzFMWZsN/AZeBsWi
	 2DjHq8osNJArTTl2HMHyi4iXTb6men/ywCw0Jz9Y+fz+gRn8fsCptqmTCMU65De9+hg8c
	 ZJoUucKQDen8EJ0/Ih8EuHXHRrv0LxE9rzPqi8AqAbm11N2GDKKbey0nHQ0SmqD+Vj1Kc
	 BA1ktju1i15eewOphpNwIyPYEowwbg3SnTCbfhMJX9j/KQyB0HT/qtH96TBgpgPO9qmfr
	 fJEhStiMfdrssAlmo314T/HuQFrOJzSpcob9okpikDDFC6aOJ+skUp2noDGsu4R9ptQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794243548;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=0LtJx1KBdKZ3ZI9o+1o9OL4PdjTAWomKB8/BPDT/SD0=;
	b=PRxzpoY0+7uCp+BWIRl6iiVt9MyPZcM9670Sz9X/N4vs5+dKzRPGkxgEIeCQDE3V4WzR
	 yWVM8rWBT2WDOXJ4ZJSA7kmWmu62VgAwyjZ0jZlQg4IP3TQjnRuomZ3fo7jnHNCxTt+MY
	 d6sHl++38BWqrNtsHpdQVkDa7Qx5N+4JFWQxvgdTx/1w7AknvHjlyIZVJHqmp1aPN+Ars
	 4pxEwbPz7hK1JZ0H/qG/1li3OLs27JJk/mD9sgiuy/mCuNYNDkOrcsyiVL1MKYIHZ/5gG
	 cUIBz5Pr6BcMu7JoxWuHm/UOzUSRi8uRi2t+NPhakmXKTZ6O7pJUyMMptb/ywpXU1Kw==
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=YkdDtHy+;
	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 AE974606A31C;
	Mon,  9 Nov 2026 16:59:07 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 206DA1F0089F;
	Mon,  9 Nov 2026 16:59:04 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794243547;
	bh=0LtJx1KBdKZ3ZI9o+1o9OL4PdjTAWomKB8/BPDT/SD0=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=YkdDtHy+qUXMzro+ShPKwWhd+3eoje6rcc8REtdlq+GzPlEKx/FX1XLP8HJIzjnCS
	 LBzu6hM+FMkCAkNgSRLhp9l6Pv5At6OagWFMo5D0n7dMk1bcXI/PAyvNiqkbro8AS5
	 22gVeGaFzTTOufvA9GvJQlafIp3J+EYshbU4T8AcT6v2WBoy6NgFBf+/Yy5uNgpc9A
	 qDPeOCMd52uH0/k32oJlx86dZWI6wimi5fyp3QaiPWHuoqjtpWHyHGTxd1jkQ+bQYn
	 SRWwmnAdKIO1wFUtG33y5asWMHolyYpQH1ImqXgZ2of5Nc/J7z40oXXsJFC33OBD0j
	 krQH/VG9PHmwA==
X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	MD Danish Anwar <danishanwar@ti.com>,
	Roger Quadros <rogerq@kernel.org>,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
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
X-In-Reply-To: <20261109165235.GR18859@horms.kernel.org>