🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13565

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

#13565
From: Xiangwu Lai
Date: Tue, 10 Nov 2026 02:38
54 lines
11482 bytes
Hi Simon,

Thanks for the review, and for looking into the neighbouring error
paths.

On Mon, Nov 09, 2026 at 04:52:35PM +0000, Simon Horman wrote:
> 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?

I don't think that branch can be entered at all, so it does not
leak in practice. eth0_node and eth1_node are both initialised to
NULL, and each iteration of the port scan loop assigns at most one
of them (the reg == 0 and reg == 1 cases are mutually exclusive),
while for_each_child_of_node() visits each child exactly once. So
the same node can never end up stored in both slots, and the
both-NULL case is already handled by the preceding "neither port0
nor port1 node available" check. As far as I can tell, the equality
comparison is dead code.

The DT error the check describes, two port nodes carrying the same
reg value, does leak a reference though, just not through that
branch: if both ports have reg = <0>, the second assignment simply
overwrites eth0_node, the reference taken on the first node is
lost, and eth1_node stays NULL, so the equality check never fires.

On Mon, Nov 09, 2026 at 04:59:02PM +0000, Simon Horman wrote:
> 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:

You are right, the error is only logged and the uninitialised value
of reg is then used to select eth0_node or eth1_node. Depending on
the garbage, the node is routed into one of the slots (including
the overwrite case above) or, when the value is neither 0 nor 1,
the reference taken by the of_node_get() right before is leaked, as
the node is not stored anywhere. This is the pre-existing loop
issue I mentioned in my reply to the bots: the "port reg should be
0 or 1" branch leaks the reference even for a valid out-of-range
reg value.

Understood on the patch-set, and thanks for the hint. I will send a
v2 that combines the fixes for the two drivers, keeping them
unchanged and adding a per-driver patch for the port scan loop that
skips a port when reading its reg property fails, only takes a
reference for reg values 0 and 1, and rejects duplicate reg values,
which is what the existing check seems to intend but never actually
catches. Happy to adjust the split if you would prefer the loop
changes as a separate series.

Best regards,
Xiangwu Lai
Technical Details
Message-ID: <20261110103000.3141-laixiangwu@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359763-linux-kernel-netdev=dewy.ru
References: <20261109165902.GS18859@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-359763-linux-kernel-netdev=dewy.ru
From: laixiangwu@cmss.chinamobile.com (Xiangwu Lai)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: ti: icssg-prueth: Fix device_node refcount leak in prueth_probe()
Date: Tue, 10 Nov 2026 10:38:30 +0800
Organization: Usenet Network
Message-ID: <20261110103000.3141-laixiangwu@cmss.chinamobile.com>
References: <20261109165902.GS18859@horms.kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="502896"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Ru8zQnNi2PbFTvVyQObOEdS3u+o= sha256:g/kBgmMId0HcNGMibiapeZCjAj9TN8D1ooMHULUD0gk=
	sha1:qIMwv9Fe5cbX3vDYyTgZcscnTVY= sha256:Pw4gwb3q+By/s7D1WvMSxs/Q3z0wlUep5idzfEexMvk=
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 ACEB01139E2; Tue, 10 Nov 2026 05:39:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
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 0ZBTSNRrfzDb;
	Tue, 10 Nov 2026 05:39:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359763-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id BE8C01139BE; Tue, 10 Nov 2026 05:39:46 +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 081DEC11B9; Tue, 10 Nov 2026 02:38:50 +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=1794278320;
	b=tdkOoLZT24zOXGuvPeduGo0SQ5/wO1KATcDmEP6o9faKzsWj6RFaZcdTySy55qabD9hJ
	 Os/UBZe0CB70GVNmzRboum75wVysID1c62G9llBBc1rVkB4rKs0jUld9Q7nHGgjtbUeWp
	 3+BHON3sl10L1B9Pjbwzsv/pcE2OK8/dOK6hXdgWTNG7wrsghUCG9+BQr8pNPCEVd1fs7
	 oiVORmorDPyCS9BJ0SX4hqC/GxhdAwpYsQjB2xR8+kJOObnozppS5V5hVjg13yUSf9Xdx
	 ni/vRObRoYJ3qMAeiljWCwH/PButjBcDEdnj7qUuNlwhdElsAfjEkdKTPD0YmUcXXLw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794278320;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=eVM5XFxpTekZI/TznZd5JXWHYNNpDG15hrmiBUopk64=;
	b=0N7XF+eaYBPUhYr61qDsoP9w9ODCzRsOBtIbGrbcy0UVyji6bfq2Jn2yKTggZmvK12SH
	 1LT9rHcbB2xw85rydVWqpfx24/wJp+8JRznogOVN52BO3kZNkiSpFMf2E8tyMRXIXt7kt
	 tphUW5nrPRjmUYk+2mvioP1qUvAKrS4XYXLbuHofcthUnkgKae0bhELdnOu4DTlg3/+Uj
	 p9BpWxpCtx4rDPUhop7BjlzDj4LyXgk+sf273FeZThGCDkDFWrfWo/8J9GJSAbiA1/Wvc
	 jfAWs3X8hhB50tbUjsx/eyh0JwavzFb7D49SFQ+BP7ZAi0UFbN98RluhytXQsO5eyhg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=co5amkzN;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	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 BAFA160A2610;
	Tue, 10 Nov 2026 02:38:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=co5amkzN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.139
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794278318;
	b=LpL2A4O3LmcDERfT6dIo6WV36hQd8Ic1SIN4oDgRXasAWAG2dS4UB2k5tBRv6+eY4NCC
	 CwDNMaSacVcf7zlIibe6Q6UrPfYNvXC1Ia4zkuuHJvRaLAo2ED1O6KrQLyGYEdvMDNSLz
	 27TvgW2h8XAcLN+mxowswiEw4A9sWHrHBfmX4r1ZaShuP4nYNYBVOdMKfeHUmrxJFUKIk
	 sVzriy02og9vNzrDPV5X/FPB5Mu+NuFwdM26BAB9rs0FWh7+l/35xaBpULROmtT8DacQE
	 C7DO+mv0qFncFDIlb/C/CP5HKQMdl7X6Pi8dPLJ1m1UxPBpAmX6ME9mQqCw9tYMDVHg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794278318;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=eVM5XFxpTekZI/TznZd5JXWHYNNpDG15hrmiBUopk64=;
	b=wIFDAPyFcBiGjzo6eN7V02jsi91l1NG35VskQuPzFI2m+JzTiEKpjaM8yILKxc/Gqzra
	 WxXu8ARzNkfKn7tZ5sj7Pa7+bZ1+gTaghBc5XXRD7HZeb8FaI0eq0rp7SsGOrnJImxPFP
	 jggshNF2LH/mvv0AcRXb8r3aZopFn9rUXpVVikNEHFaJLc9TvEJuQpXyLw2e2wjfmNp/x
	 Dj6P3irNjC/82K+aeykfgvNqaGojVjyEGy9y4weebuJgpZ1VLqcvhP4hgMvp0FTrdx2Gl
	 tfZIEw/FA5Mkbr4eJKnGhXY1mgqZbt3kGEpSDHhF9aaw/pFRqsCRey4gZ9ssSFEhdHA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=co5amkzN;
	arc=none smtp.remote-ip=111.22.67.139
X-Received: from cmccmta6.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 369AB60A260D;
	Tue, 10 Nov 2026 02:38:35 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 369AB60A260D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=co5amkzNgSM4eSt5maBYOipTvdJoD6KKIekUMjO8V3MWhhzeyX9HKO0FPrl7hK+x6rW87jGNkhQv1
	 g2Mj+zIRy1+f7dzbSNu8JqA0UpxsDc5rFRGiPSTc19Onygrz2M6IEz9LAxzagDCIwyHqQD0+7K6Miq
	 1EQC0kK4WHuGSd9o=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app05-12005 (RichMail) with SMTP id 2ee56af283a8b65-c70bd;
	Tue, 10 Nov 2026 10:38:34 +0800 (CST)
X-RM-TRANSID: 2ee56af283a8b65-c70bd
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from DESKTOP-3K8GUTQ (unknown[223.108.79.98])
	by rmsmtp-syy-appsvr05-12005 (RichMail) with SMTP id 2ee56af283a8745-a37b7;
	Tue, 10 Nov 2026 10:38:34 +0800 (CST)
X-RM-TRANSID: 2ee56af283a8745-a37b7
X-Cc: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>,
	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>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Diogo Ivo <diogo.ivo@siemens.com>,
	Haokexin <haokexin@gmail.com>,
	netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.50.1.windows.1
X-In-Reply-To: <20261109165902.GS18859@horms.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