Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()
@ 2026-12-04  6:15 mdshahid03
  2026-12-04  6:16 ` netdev-bot+sinfo
  2026-12-05  6:19 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: mdshahid03 @ 2026-12-04  6:15 UTC (permalink / raw)
  To: netdev; +Cc: andrew+netdev, davem, edumazet, kuba, pabeni, Mohammad Shahid

From: Mohammad Shahid <mdshahid03@gmail.com>

Check the return value of _ti_tpi_read before using the value
read from the MI1 register.

When the TPI read fails, the output variable is not initialized.
Using it to check the MI1 busy bit can result in an uninitialized
value being accessed.

Return immediately when the TPI read fails to avoid accessing the
uninitialized variable.

Fixes: 8199d3a79c22 ("[PATCH] A new 10GB Ethernet Driver by Chelsio Communications")
Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 drivers/net/ethernet/chelsio/cxgb/subr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb/subr.c b/drivers/net/ethernet/chelsio/cxgb/subr.c
index d4488e400bc6..bb42155d273a 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;
+
 		busy = val & F_MI1_OP_BUSY;
 		if (busy)
 			udelay(10);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()
  2026-12-04  6:15 [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready() mdshahid03
@ 2026-12-04  6:16 ` netdev-bot+sinfo
  2026-12-05  6:19 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04  6:16 UTC (permalink / raw)
  To: mdshahid03; +Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()
  2026-12-04  6:15 [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready() mdshahid03
  2026-12-04  6:16 ` netdev-bot+sinfo
@ 2026-12-05  6:19 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05  6:19 UTC (permalink / raw)
  To: mdshahid03; +Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:15 [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready() mdshahid03
2026-12-04  6:16 ` netdev-bot+sinfo
2026-12-05  6:19 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox