mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Pavan Chebbi <pavan.chebbi@broadcom.com>,
	Michael Chan <michael.chan@broadcom.com>,
	 Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev,  Elkin Cruz <elkin@google.com>,
	Ian Rogers <irogers@google.com>
Subject: [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()
Date: Tue, 24 Nov 2026 16:42:31 -0800	[thread overview]
Message-ID: <20261125004231.1007868-1-irogers@google.com> (raw)

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, &reg32);
 	if (err)
-- 
2.56.1.831.g720f3f5937-goog


                 reply	other threads:[~2026-11-25  0:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125004231.1007868-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=elkin@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.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

all inboxes | Powered by JetHome®