🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24031

Re: [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000 in tg3_phy_reset_5703_4_5()

#24031
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 00:55
107 lines
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, &reg32);
>  	if (err)

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125004231.1007868-1-irogers%40google.com
Technical Details
Message-ID: <179591373694.3135.13755573347057829013@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373326-linux-kernel-netdev=dewy.ru
References: <20261125004231.1007868-1-irogers@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373326-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3] tg3: Avoid writing uninitialized MII_CTRL1000
 in tg3_phy_reset_5703_4_5()
Date: Sun, 29 Nov 2026 00:55:36 +0000
Organization: Usenet Network
Message-ID: <179591373694.3135.13755573347057829013@kernel.org>
References: <20261125004231.1007868-1-irogers@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1072672"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:EfaPQUPfumGX0S2hXUB5cPoaCEg= sha256:PIhEDFJj1UY9kbSsB3dl5SZScynZrWGgUL024b9ZCK8=
	sha1:E3AFqu3iPsWuahMayRUOt2XAQqA= sha256:8RI9/hbpsea5QTL5RqyACWvbHQ6OZtEF8wgsJVpnXIc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8501E125F8D; Sun, 29 Nov 2026 04:03:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 0BV17F3zVuPT;
	Sun, 29 Nov 2026 04:03:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373326-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 5A7D8125F88; Sun, 29 Nov 2026 04:03:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 72EF127094; Sun, 29 Nov 2026 00:55:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795913744;
	b=3/gdIaRB4TWtK9kY4m5mhHDHYTtjD7lhr3DhkK1ichh/vOmaMLViQ6+AMpT7IpMDbctu
	 iWgCFdi5GwIoVv85g+4PvBhuCt8yp5ZL0Au5PFnffZ67d0MHyzG5QFapso4Q5DQqzrAYp
	 oxflNGZ3Kjd4J4FUo8ydkJ1QiM9Euqdc83rtr050jzqGojgHOHYuWRpZlUIaTVES6wnhu
	 KVjpMd6XdQs+BaAKDYDW61dUEbPw6TxffW5boDeai+NtaNGaMCFAP48Ia99KJKJn9JfAH
	 t/J7gkPRNwVCMC55jXMu4DIbl9UeKBDc6HDqmSQqYmdqPmGIrFhDk0Ti4XenxZ2vTmw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795913744;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=BHHHL6fvQ9YVlyMg5vjWWuVfocn6B3SBEqZ3a026HH4=;
	b=1aUtbYRkPpBm5E6Bl0fFKcu/XGrEMqzNJwLiEq5m3rijCLLVhRxs3juKRC4KVRu2Hzrh
	 ju/SdUCcZc7/6CN42/Kn5QlLkWmhEfjqRqz3lp81y8nZNuhfYJaWb7Rw9u0deGNBwMIp1
	 SV2VXB4+KOdEnxRA564cWJdfwHz2gWaDlRJx0pvElNzVWeUWRombT8BD9AxvGDLoouUQM
	 nOpaKbG4zVZ7c8EWs31RUJ4bVsnMme+ZF3MpiwWHQN+0rHbZCoDQeslYeXvLU89kXFHDZ
	 H71xqhgFBGZ8y3YzMbQ1zpGw4lZBASco6t8A3b26CCuXfXgIPTxgSy789XLmsRBRqxw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fRf01XEp;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4857E606A325;
	Sun, 29 Nov 2026 00:55:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fRf01XEp
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795913738;
	b=K/5b6OoiyVLZPvq3gkd0h9GOSHUGoAWOn9Pdj1pxPsasUbxUmUZHKWjP5BBYqI/H0ftb
	 aIS54i0rt2CKP0C86e8T+ML1w9/dZxKC0/xljtuHAdjMD2IgPFwTHOs/1ogSnEajbQ5LI
	 mU2TJY+/HXbcWje34YvqsGEc6mup3lV00ZzzU5h2dULWtssnJk1CrkQA0TGkyBJ49fngS
	 wkpur3ru4tX6pGxWe/b4AiE3bEJ3DF4UYy3D/em1ktpRThwxquqzmv7uPLw0gssqqeoWv
	 g2z3BtA51q2DgoXRwCMe7PE0q/VGcwBrhyOAphrn6FHxITwDnF/nR4QQTEvGtMnN7yQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795913738;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=BHHHL6fvQ9YVlyMg5vjWWuVfocn6B3SBEqZ3a026HH4=;
	b=XXlWIoUdFIaKCMFS3aadInYWsQY2V9V7kYyxehxaUCAPfFukDbj10zHtyQGtsXih8FNT
	 YD2fJna1iwzPVaImzMlHie/xXz4YhNHqCMP7XPIkko+1dUzXi6Ff+AA2tHg0jAUx3KdNa
	 GIY86UoylQ2kt9D0q+ETcT4LMRA/CGvIM9mcZXIoEEddLiG4rWUgbM7YqgyqlIc+pcuWw
	 v7bwbvLw1Mg7eoaLMGuwzNCOT3Qwz9vpzaUJeN6tzYLNR2uLptRWGt3bE41jKfbWRBT3Z
	 nIMaVHBU8ELMtdOhym2bVBy+kUSnkpmGBnjUo9/GcaKklJwJQIq0kcVWKxn8H1VBCHg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fRf01XEp;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63E8B606A323;
	Sun, 29 Nov 2026 00:55:38 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 632A61F000C1;
	Sun, 29 Nov 2026 00:55:37 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795913738;
	bh=BHHHL6fvQ9YVlyMg5vjWWuVfocn6B3SBEqZ3a026HH4=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=fRf01XEpNRhgx3r/NqRYabZAz+oUJXJJRBGw4x6z6unwVIEhdq1EV15NHZnOpwtmG
	 eqeC48vor4i7y4ahybWH87A6PZRLWWadqJCCG2PXrUkBt4QRpppos+LfXe+JkULFPd
	 kT8oWBedtCB+jpcN6RMwt3XfuU/FZDuH5g0h6kUWhSyHsKySCugwERQyh+sLo5L+9a
	 b9buo8k49VwRSyVQ3wj4bs2OBxjGbXOGE2NAnJ57eJLgGneA2GQ9bfXKEuNhUCUxv5
	 5+5QS+mKPDoHy/ZkTlvpQ1p0yUPScJLeYVWGvsE3JQyqhw+x3ncN9G6FPgckYO5vzl
	 wK4z3UY03ASoQ==
X-Cc: pavan.chebbi@broadcom.com, michael.chan@broadcom.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org, llvm@lists.linux.dev, elkin@google.com
X-In-Reply-To: <20261125004231.1007868-1-irogers@google.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list