* [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()
@ 2026-11-25 0:42 Ian Rogers
2026-11-29 0:55 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-25 0:42 UTC (permalink / raw)
To: Pavan Chebbi, Michael Chan, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, llvm, Elkin Cruz, Ian Rogers
In tg3_phy_reset_5703_4_5(), if MDIO reads fail across all 10 iterations
of the retry loop before MII_CTRL1000 is read, phy9_orig is never
populated before being written back to MII_CTRL1000 during post-loop
cleanup.
Track whether MII_CTRL1000 was successfully read with a phy9_orig_set
flag and only restore MII_CTRL1000 when phy9_orig_set is true, while
keeping the existing post-loop DSP and MII_TG3_EXT_CTRL cleanup intact
when tg3_phy_write_and_check_testpat() exhausts its retries. Also
zero-initialize phy9_orig because Clang's value-insensitive
-Wconditional-uninitialized check does not correlate phy9_orig_set with
phy9_orig.
Discovered via Clang -Wconditional-uninitialized on an x86_64
allyesconfig build with AI coding assistant help. Verified by building
drivers/net/ethernet/broadcom/tg3.o with LLVM=1 W=1 (-Werror) and
-Wconditional-uninitialized; not runtime-tested on BCM5703/5704/5705
hardware.
Signed-off-by: Ian Rogers <irogers@google.com>
---
Notes:
v3:
- Keep the post-loop DSP/MII_TG3_EXT_CTRL restore sequence intact when
test-pattern retries are exhausted instead of returning early with the
PHY transmitter disabled and DSP 0x8005 blocked, and drop the
inaccurate tg3_phy_probe() claim from the commit message (Sashiko AI
review).
- Guard the MII_CTRL1000 writeback with phy9_orig_set.
v2: https://lore.kernel.org/r/20261122045326.19641-1-irogers@google.com
- Target net-next, drop the Fixes tag (Andrew Lunn), and zero-initialize
phy9_orig.
v1: https://lore.kernel.org/r/20261119171021.1535172-1-irogers@google.com
drivers/net/ethernet/broadcom/tg3.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 95827df4cf6a..21d21fb2b016 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -2544,8 +2544,9 @@ static int tg3_phy_reset_chanpat(struct tg3 *tp)
static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
{
- u32 reg32, phy9_orig;
int retries, do_phy_reset, err;
+ bool phy9_orig_set = false;
+ u32 reg32, phy9_orig = 0;
retries = 10;
do_phy_reset = 1;
@@ -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);
err = tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32);
if (err)
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()
2026-11-25 0:42 [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5() Ian Rogers
@ 2026-11-29 0:55 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29 0:55 UTC (permalink / raw)
To: irogers
Cc: pavan.chebbi, michael.chan, andrew+netdev, davem, edumazet, kuba,
pabeni, netdev, linux-kernel, llvm, elkin
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 0:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 0:42 [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5() Ian Rogers
2026-11-29 0:55 ` 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