Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by netdev-bot+sashiko
Sun, 29 Nov 2026 00:55
Re: [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()
Author: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 00:55
Date: Sun, 29 Nov 2026 00:55
107 lines
11409 bytes
11409 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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).
- [Medium] In tg3_phy_reset_5703_4_5()
(drivers/net/ethernet/broadcom/tg3.c), the new phy9_orig_set flag is…
--
tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()
This patch adds a phy9_orig_set flag to tg3_phy_reset_5703_4_5(). The
flag records that MII_CTRL1000 was read, and the post-loop restore of
MII_CTRL1000 now only happens when the flag is set. It also
zero-initializes phy9_orig to quiet Clang's -Wconditional-uninitialized
warning.
> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 95827df4cf6a1..21d21fb2b0161 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c
[ ... ]
> @@ -2571,6 +2572,7 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
> /* Set to master mode. */
> if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig))
> continue;
> + phy9_orig_set = true;
>
> tg3_writephy(tp, MII_CTRL1000,
> CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER);
> @@ -2598,7 +2600,8 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
>
> tg3_phy_toggle_auxctl_smdsp(tp, false);
>
> - tg3_writephy(tp, MII_CTRL1000, phy9_orig);
> + if (phy9_orig_set)
> + tg3_writephy(tp, MII_CTRL1000, phy9_orig);
[Severity: Medium]
Can this still write 0 to MII_CTRL1000 when phy9_orig_set is true?
Once phy9_orig_set is set it stays set. But every pass of the retry loop
reads MII_CTRL1000 straight into phy9_orig. __tg3_readphy() clears the
output before the MDIO transaction and only fills it in on success:
drivers/net/ethernet/broadcom/tg3.c:__tg3_readphy() {
...
*val = 0x0;
...
ret = -EBUSY;
if (loops != 0) {
*val = frame_val & MI_COM_DATA_MASK;
ret = 0;
}
...
}
So consider this sequence:
iteration N: tg3_readphy(MII_CTRL1000) succeeds, phy9_orig_set = true
tg3_phy_write_and_check_testpat() fails, loop retries
iteration N+k: tg3_readphy(MII_TG3_EXT_CTRL) succeeds
tg3_readphy(MII_CTRL1000) times out, phy9_orig = 0
continue (phy9_orig_set is still true)
no later iteration succeeds
Here the guarded restore writes 0 to MII_CTRL1000. That clears the
1000BASE-T advertisement and the master/slave settings.
The commit message says:
Track whether MII_CTRL1000 was successfully read with a phy9_orig_set
flag and only restore MII_CTRL1000 when phy9_orig_set is true
In this case, though, the value being restored comes from a read that
failed.
Would it work to read into a temporary and latch phy9_orig only on the
first successful read? For example:
if (tg3_readphy(tp, MII_CTRL1000, &tmp))
continue;
if (!phy9_orig_set) {
phy9_orig = tmp;
phy9_orig_set = true;
}
That would also stop later iterations from replacing the saved value with
the CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER value the loop itself wrote
on an earlier pass.
>
> err = tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32);
> if (err)
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125004231.1007868-1-irogers%40google.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads