From: netdev-bot+sashiko@kernel.org
To: mdshahid03@gmail.com
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com
Subject: Re: [PATCH] net: cxgb: fix uninitialized variable in mi1_wait_until_ready()
Date: Sat, 05 Dec 2026 06:19:45 +0000 [thread overview]
Message-ID: <179645158599.3146.11396515266545524981@kernel.org> (raw)
In-Reply-To: <20261204061548.59242-1-mdshahid03@gmail.com>
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
prev parent reply other threads:[~2026-12-05 6:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179645158599.3146.11396515266545524981@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=mdshahid03@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox