🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27263

Re: [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()

#27263
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 06:19
156 lines
13597 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1 (1)

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 fix is incomplete: the same uninitialized-value bug after a
  failed TPI read of an MI1 register is still present a few lines…
- [Low] net: cxgb: commit message misspells __t1_tpi_read() as
  _ti_tpi_read

Pre-existing issues:
- [Low] All six call sites ignore the return value of
  mi1_wait_until_ready(): mi1_mdio_read (subr.c:299), mi1_mdio_write…

--

net: cxgb: fix uninitialized variable in mi1_wait_until_ready()

This patch checks the return value of __t1_tpi_read() in
mi1_wait_until_ready(). When the TPI read fails, the function now returns
1 straight away, so it never tests the busy bit on an uninitialized val.

> diff --git a/drivers/net/ethernet/chelsio/cxgb/subr.c b/drivers/net/ethernet/chelsio/cxgb/subr.c
> index d4488e400bc6e..bb42155d273a1 100644
> --- a/drivers/net/ethernet/chelsio/cxgb/subr.c
> +++ b/drivers/net/ethernet/chelsio/cxgb/subr.c
> @@ -255,7 +255,9 @@ static int mi1_wait_until_ready(adapter_t *adapter, int mi1_reg)
>  	do {
>  		u32 val;
>  
> -		__t1_tpi_read(adapter, mi1_reg, &val);
> +		if (__t1_tpi_read(adapter, mi1_reg, &val))
> +			return 1;
> +

[Severity: Low]
This is a minor changelog nit. The commit message says:

  Check the return value of _ti_tpi_read before using the value

The function whose return value this hunk now checks is __t1_tpi_read().
It has two leading underscores and "t1" with the digit one, not
"_ti". As written, the changelog names a symbol that does not exist.
Anyone grepping git log for __t1_tpi_read later will not find this
commit.

There is no runtime impact. Could you spell the function name correctly
when you respin, preferably as __t1_tpi_read() with the trailing
parentheses?

[Severity: High]
Is this fix complete? The same uninitialized read after a failed TPI read
of an MI1 register is still there a few lines further down the same MDIO
path.

__t1_tpi_read() only writes *valp when t1_wait_op_done() succeeds:

drivers/net/ethernet/chelsio/cxgb/subr.c:__t1_tpi_read() {
    ...
	if (tpi_busy)
		pr_alert("%s: TPI read from 0x%x failed\n",
			 adapter->name, addr);
	else
		*valp = readl(adapter->regs + A_TPI_RD_DATA);
	return tpi_busy;
}

mi1_mdio_read() and mi1_mdio_ext_read() both declare val without
initializing it. Neither checks the return value of the wait or of the
final data read, and both return val unconditionally:

drivers/net/ethernet/chelsio/cxgb/subr.c:mi1_mdio_ext_read() {
	unsigned int val;
    ...
	mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);

	/* Read the data. */
	__t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val);
	spin_unlock(&adapter->tpi_lock);
	return val;
}

mi1_mdio_read() follows the same pattern.

Every caller ignores the new return 1 from mi1_wait_until_ready(). So
after the TPI failure described in the commit message, execution goes
straight on to the unchecked MI1_DATA read. The uninitialized value then
leaves the function, where before it only fed a local busy-bit test.

>From there it reaches cphy_mdio_read(), which only treats negative
returns as errors:

drivers/net/ethernet/chelsio/cxgb/cphy.h:cphy_mdio_read() {
	int rc = cphy->mdio.mdio_read(cphy->mdio.dev, cphy->mdio.prtad, mmd,
				      reg);
	*valp = (rc >= 0) ? rc : -1;
	return (rc >= 0) ? 0 : rc;
}

The PHY drivers (mv88e1xxx, mv88x201x, my3126) use that value for link,
speed and duplex decisions. They also use it for read-modify-write of PHY
control registers.

It can also come back through t1_ioctl()->mdio_mii_ioctl() as the
SIOCGMIIREG val_out. That would expose stack contents to a CAP_NET_ADMIN
caller.

Should mi1_mdio_read() and mi1_mdio_ext_read() check the __t1_tpi_read()
result, or initialize val, and return a negative errno such as -EIO?
cphy_mdio_read() already expects that. Should mi1_wait_until_ready()
failures be propagated as well?

[Severity: Low]
This is a pre-existing issue, not one introduced by this patch, but none
of the callers act on the new early return. All six mi1_wait_until_ready()
call sites ignore its return value: mi1_mdio_read(), mi1_mdio_write(),
mi1_mdio_ext_read() (twice) and mi1_mdio_ext_write() (twice).

In the clause-45 paths, the INDIRECT_READ or INDIRECT_WRITE phase is issued
even if the INDIRECT_ADDRESS phase never completed:

drivers/net/ethernet/chelsio/cxgb/subr.c:mi1_mdio_ext_write() {
    ...
	mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);

	/* Write the data. */
	__t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val);
	__t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_WRITE);
	mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
	spin_unlock(&adapter->tpi_lock);
	return 0;
}

mi1_mdio_write() and mi1_mdio_ext_write() also return 0 unconditionally.
A PHY write that failed is therefore reported as a success.

The existing busy timeout (return busy with busy set) was already ignored
by these callers before this patch. The patch only replaces undefined
behaviour with a fixed early return.

Could this be addressed together with the fix above, by returning -EIO
from the MDIO accessors when mi1_wait_until_ready() fails?

>  		busy = val & F_MI1_OP_BUSY;
>  		if (busy)
>  			udelay(10);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204061548.59242-1-mdshahid03%40gmail.com
Technical Details
Message-ID: <179645158599.3146.11396515266545524981@kernel.org>
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377850-linux-kernel-netdev=dewy.ru
References: <20261204061548.59242-1-mdshahid03@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377850-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()
Date: Sat, 05 Dec 2026 06:19:45 +0000
Organization: Usenet Network
Message-ID: <179645158599.3146.11396515266545524981@kernel.org>
References: <20261204061548.59242-1-mdshahid03@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2967265"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0UzFgaZZROFuigfeUhxgFuAfIZs= sha256:dKdv8Nm7atw6ks6OET4k4Rs+v4t1lyFYbajagwMCPck=
	sha1:FpXArq09vOVNoiZ+PmzaD87Qink= sha256:CjC/1lQ8a7mqalZE6CTDM/iyCUn4BU9FyrWXwFgTTCA=
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 2F71B117D4A; Sat,  5 Dec 2026 09:20:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 7fNLCU5_Knrr;
	Sat,  5 Dec 2026 09:20:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377850-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 90356117D62; Sat,  5 Dec 2026 09:19:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 46F922FD6B; Sat,  5 Dec 2026 06:19:48 +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=1796451588;
	b=SjICJwqVrBZrQiYpRbNtwMIkkF095qdkLpSOmaGfFm2X8Dofcc1W7qTLPBWzb5yRE01O
	 hRmvZbJN1uiXnYCSzyxqaQZrfoYvjQevRZUrehG4aDujQpt/0IELFvIASo03E0tfJEBzT
	 uI/27Uv9EtvdQUtxeIBrpdgSaaUtUISWX2adU6vzIlZx3dvWpSFooNzQ284oHcXFS33MP
	 wJyAAzcSt8NRAMkEvGwLXNt+gVdyIeO75O2cDw5UhUb53exDOe4LyShj4i5GwkIaLRQoP
	 ypyKDdnOrrdDL/L8XjzLg1BrwOjVhYhGGspao8mNUwHhPkDVQ8kCm18WhBhWgCoF7Xw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796451588;
	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=47qtHBiJu6C1VX0F2Z8YuNDtzM264+QQSxtTmRI/4M0=;
	b=eNxUxNo0mCiBsNadovWdwsF2Oys0EOE/m2XRZ8LuKhFnxd45n3ZUZytHv8IO/pHVBIl6
	 VrIqNlKy/vKHQnIMhZ3oFY2/rcD/pwUBMlGF0/Rc2mCCaFIKh/BF/5udRFEaq9yCRLKYM
	 Uj4J0gpGFO07dwNBv7CmwW5Ys9U5QSi//IK5yH/rSGBXEM3HbTVjCEQacNxC64YEPQNfW
	 zxhmu8b8jhfum32wjcIDftPshKUKun11C8GxIQVUi2mgVSiAViz3eI1VUYG6FxR6A6OlT
	 dalktmsCc9ib6TSN2bERVcm0DGOrfnXZPeYbP8f8hfNfs9e+ovCKsQ6LjOBB+iSg8xg==
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=fiw7mtBM;
	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 1D655606A334;
	Sat,  5 Dec 2026 06:19:48 +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=fiw7mtBM
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=1796451587;
	b=lkP0AndWW4lK4stW6xRukqJ9TvfoudoaQNzj52+tlMpi7pyxYdRRhF+FT4qTxuF03tJa
	 OuCWh+0G9da3ofiTO6JqUZ8WuDhLQ0AZMfWqGlr+g7L/wstuqTMNNhtjoKPySYVeGrFv7
	 AA5flVvuY4NCMMB1n2ZhhcKl9NGONVNRFwBWvsyu9U4jK6fjn6zz0/dqWBLl9bdyciZIX
	 hPqJyQqECEL2eUQNXlk12cy8uWbKukmKLD1zKWSCAp3IMSybC4TdzR3LHBJMk0Y7wWwSL
	 fYc8DQeKLSo+FN/D85HuofYgW7zwa6hKZO0wS58KXkoudidr2viVT/YHzyejooqWm1A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796451587;
	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=47qtHBiJu6C1VX0F2Z8YuNDtzM264+QQSxtTmRI/4M0=;
	b=ZyXz1mys0X4Rqsz4NE8kUPQjK5ANB5CV0P0DMS4eTjVUFg8D1eq7jlw8BaxPdigWkXsR
	 L/w738QlWVu3K21yE7V1ihqaj5r/qUPwmv2y0/NiA5KecBvYi0fXERPz74wuYkNJH8a12
	 nKnd1OeWmg+DyQ5AFY7wVD0zyf5mYUDeTRzy+zsOQQ/eoVRLjUz5UL51s3uozWDyJY8Pg
	 GZ5UVjpvjgidh4kRN+dRYeoJu5sA41m2BrTdvx2OmHS2LbWUQhYDKbT21Ia7kv37NJCWU
	 fgqJ6JShl9yopspVJ4TEUzhxTsbys6+Gw9nLapMze3yhRityf46LNFJgfcrwmapkP6w==
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=fiw7mtBM;
	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 3D5AB606A322
	for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 06:19:47 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75A9F1F00936;
	Sat,  5 Dec 2026 06:19:46 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796451586;
	bh=47qtHBiJu6C1VX0F2Z8YuNDtzM264+QQSxtTmRI/4M0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=fiw7mtBM0/b0oC3URE6zzHX50UOT4b4PeTbH7Sh2RtmC2On0v6RNs0esxor/4l5j2
	 NgGur6xUcKJBgb4xnqDWj/IxzVj6yXOc2qYlgZbhe17Jg0LdH+muiIytIQDqL8l/MW
	 HWOMFfw4wuzgqdLrBhgUq/5ay3d2moFZwT6CkCBtPITyg0GPL6acFgqQ1AhCzLd0NA
	 wrIZMAPuNGX/flSNHtpZ7AtReRrMRUBRQ8ZsB7mG3ZNobElG4GmSDau0nUzJRCJJum
	 9JzfntxLJHEemDR0bnAwBwvewP0HplnNLB7bjDVoSeYMI96eyqO2TYmoL27uTYCscl
	 wQppxSe5ae82g==
X-Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
X-In-Reply-To: <20261204061548.59242-1-mdshahid03@gmail.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