* [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
@ 2026-11-19 17:10 Ian Rogers
2026-11-19 20:15 ` Andrew Lunn
2026-11-23 19:17 ` netdev-bot+sashiko
0 siblings, 2 replies; 5+ messages in thread
From: Ian Rogers @ 2026-11-19 17:10 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(), the 10-iteration retry loop discards the
return value of both tg3_readphy() calls on continue and never checks
err after the loop terminates. If MDIO reads fail across all 10
retries, phy9_orig is never initialized before being written back to
MII_CTRL1000; if tg3_phy_write_and_check_testpat() fails across all 10
retries, the function silently continues as if the PHY test pattern
succeeded.
Record err on both tg3_readphy() calls and return err if the retry
loop finishes with an error.
Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
build. 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.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/net/ethernet/broadcom/tg3.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 95827df4cf6a..be2410e718fd 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -2558,7 +2558,8 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
}
/* Disable transmitter and interrupt. */
- if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32))
+ err = tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32);
+ if (err)
continue;
reg32 |= 0x3000;
@@ -2569,7 +2570,8 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
BMCR_FULLDPLX | BMCR_SPEED1000);
/* Set to master mode. */
- if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig))
+ err = tg3_readphy(tp, MII_CTRL1000, &phy9_orig);
+ if (err)
continue;
tg3_writephy(tp, MII_CTRL1000,
@@ -2587,6 +2589,9 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
break;
} while (--retries);
+ if (err)
+ return err;
+
err = tg3_phy_reset_chanpat(tp);
if (err)
return err;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
2026-11-19 17:10 [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5() Ian Rogers
@ 2026-11-19 20:15 ` Andrew Lunn
2026-11-20 17:16 ` Ian Rogers
2026-11-23 19:17 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2026-11-19 20:15 UTC (permalink / raw)
To: Ian Rogers
Cc: Pavan Chebbi, Michael Chan, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
llvm, Elkin Cruz
On Thu, Nov 19, 2026 at 09:10:21AM -0800, Ian Rogers wrote:
> In tg3_phy_reset_5703_4_5(), the 10-iteration retry loop discards the
> return value of both tg3_readphy() calls on continue and never checks
> err after the loop terminates. If MDIO reads fail across all 10
> retries,
If it fails 10 times, the hardware is dead, and there is no
recovery. The best you can do is make the probe fail.
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
This clearly does not bother anybody.
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
2026-11-19 20:15 ` Andrew Lunn
@ 2026-11-20 17:16 ` Ian Rogers
2026-11-20 23:20 ` Andrew Lunn
0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2026-11-20 17:16 UTC (permalink / raw)
To: Andrew Lunn
Cc: Pavan Chebbi, Michael Chan, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
llvm, Elkin Cruz
On Thu, Nov 19, 2026 at 12:15 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Thu, Nov 19, 2026 at 09:10:21AM -0800, Ian Rogers wrote:
> > In tg3_phy_reset_5703_4_5(), the 10-iteration retry loop discards the
> > return value of both tg3_readphy() calls on continue and never checks
> > err after the loop terminates. If MDIO reads fail across all 10
> > retries,
>
> If it fails 10 times, the hardware is dead, and there is no
> recovery. The best you can do is make the probe fail.
Agreed - propagating err out of tg3_phy_reset_5703_4_5() does make
probe fail via:
tg3_init_one() -> tg3_get_invariants() -> tg3_phy_probe() -> tg3_phy_reset()
rather than falling through and passing an uninitialized phy9_orig to
tg3_writephy() (which is an 'i32 noundef' UB in Clang -O2 IR when
CONFIG_INIT_STACK_NONE=y).
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> This clearly does not bother anybody.
>
> https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Fair point - sending this as [PATCH net] with Fixes: for stable was
wrong. The motivation is cleaning up Clang -Wconditional-uninitialized
warnings across allyesconfig so the warning can eventually be enabled.
Would you take this for net-next without the Fixes: tag (or a minimal
'phy9_orig = 0' initialization if you prefer not touching the old
control flow), or would you rather leave tg3 alone?
Thanks,
Ian
> Andrew
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
2026-11-20 17:16 ` Ian Rogers
@ 2026-11-20 23:20 ` Andrew Lunn
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2026-11-20 23:20 UTC (permalink / raw)
To: Ian Rogers
Cc: Pavan Chebbi, Michael Chan, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
llvm, Elkin Cruz
> Would you take this for net-next without the Fixes: tag
Yes.
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
2026-11-19 17:10 [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5() Ian Rogers
2026-11-19 20:15 ` Andrew Lunn
@ 2026-11-23 19:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 19:17 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 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 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] In tg3_phy_reset_5703_4_5()
(drivers/net/ethernet/broadcom/tg3.c), the patch adds an `if (err)…
- [Low] The commit message says the patch was prompted by Clang
-Wconditional-uninitialized on phy9_orig and was verified by building…
--
tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()
This patch saves the return values of the two tg3_readphy() calls in the
tg3_phy_reset_5703_4_5() retry loop. If the loop finishes with an error,
the function now returns it. The goal is to avoid writing an uninitialized
phy9_orig back to MII_CTRL1000, and to stop treating a failed test pattern
as success.
> Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
> build. 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.
[Severity: Low]
Will Clang still warn about phy9_orig with -Wconditional-uninitialized
after this change?
phy9_orig is still declared without an initializer:
u32 reg32, phy9_orig;
There is still a path where every iteration takes the first continue
(the MII_TG3_EXT_CTRL read fails) before &phy9_orig is ever passed to
tg3_readphy().
Clang's uninitialized-values analysis does not link err to phy9_orig. So
the new "if (err) return err;" after the loop should not change what it
reports for this later use:
tg3_writephy(tp, MII_CTRL1000, phy9_orig);
At runtime the patch is correct here. err == 0 after the loop can only
happen through the break, and that needs a successful MII_CTRL1000 read.
Is an explicit initializer or a restructured loop needed to silence the
warning? Or should the verification statement in the commit message be
changed?
> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 95827df4cf6a1..be2410e718fd9 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c
[ ... ]
> @@ -2587,6 +2589,9 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
> break;
> } while (--retries);
>
> + if (err)
> + return err;
> +
[Severity: High]
Can this early return leave the PHY in its test configuration?
By the time a pass reaches tg3_phy_write_and_check_testpat(), the loop
has already done the following:
- set EXT_CTRL |= 0x3000 (transmitter and interrupt disabled)
- forced MII_BMCR to 1000/full duplex
- forced MII_CTRL1000 to master
- enabled SMDSP
- blocked PHY control access:
/* Block the PHY control access. */
tg3_phydsp_write(tp, 0x8005, 0x0800);
When the test pattern does not match, tg3_phy_write_and_check_testpat()
returns -EBUSY without setting *resetp. MDIO is still working at that
point:
if (low != test_pat[chan][i] ||
high != test_pat[chan][i+1]) {
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);
return -EBUSY;
}
If that happens on all 10 retries, err is -EBUSY when the loop exits.
Before this patch, tg3_phy_reset_chanpat() overwrote err. When it
succeeded, the function went on to undo the setup:
tg3_phydsp_write(tp, 0x8005, 0x0000);
...
tg3_phy_toggle_auxctl_smdsp(tp, false);
tg3_writephy(tp, MII_CTRL1000, phy9_orig);
...
reg32 &= ~0x3000;
tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
It then returned 0, so tg3_phy_reset() also applied its out: workarounds
(ADC_BUG, 5704_A0_BUG, BER/JITTER_BUG, EXTPKTLEN, FIFO_ELASTIC, automdix,
wirespeed).
With the early return, tg3_phy_reset() now returns before it reaches the
out: label:
err = tg3_phy_reset_5703_4_5(tp);
if (err)
return err;
goto out;
Most callers ignore the return value of tg3_phy_reset(). One example is
tg3_reset_hw():
if (reset_phy)
tg3_phy_reset(tp);
tg3_setup_copper_phy(), the fiber and SGMII setup paths, the ethtool
self-test and tg3_set_eee() also ignore it.
Wouldn't those callers carry on with the transmitter disabled and DSP
control access still blocked?
tg3_phy_probe() does pass the error up. tg3_get_invariants() then calls
tg3_mdio_fini() and returns err, and tg3_init_one() aborts the probe.
Hardware that keeps hitting the mismatch used to be restored and keep
working. Does it now fail to probe?
Would a shared unwind path work better here? Before returning the error,
it could:
- unblock 0x8005
- turn SMDSP off
- clear EXT_CTRL 0x3000
- restore MII_CTRL1000 only if it was actually read, or do a BMCR reset
Should running out of test pattern retries be fatal at all? The commit
message also doesn't mention this change in behavior.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119171021.1535172-1-irogers%40google.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 19:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:10 [PATCH net] tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5() Ian Rogers
2026-11-19 20:15 ` Andrew Lunn
2026-11-20 17:16 ` Ian Rogers
2026-11-20 23:20 ` Andrew Lunn
2026-11-23 19:17 ` 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
all inboxes | Powered by JetHome®