Skip to contentSkip to conversation

broadcom: b44: prevent uninitialized value usage

PATCH Superseded Alexey Simakov 3 participants 4 messages Dec 4, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 broadcom: b44: prevent uninitialized value usage

On execution path with raised B44_FLAG_EXTERNAL_PHY, b44_readphy() leaves bmcr value uninitialized and it is used later in the code.

Add check of this flag at the beginning of the b44_nway_reset() and exit early of the function if an external PHY is used, that would also correspond to other b44_readphy() call sites.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes 753f492093da ("[B44]: port to native ssb support")
---
 drivers/net/ethernet/broadcom/b44.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/b44.c +3 -0
index 0353359c3fe9..cbfd65881326 100644
@@ -1789,6 +1789,9 @@ static int b44_nway_reset(struct net_device *dev)
 	u32 bmcr;
 	int r;
 
+	if (bp->flags & B44_FLAG_EXTERNAL_PHY)
+		return 0;
+
 	spin_lock_irq(&bp->lock);
 	b44_readphy(bp, MII_BMCR, &bmcr);
 	b44_readphy(bp, MII_BMCR, &bmcr);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Alexey Simakov

On execution path with raised B44_FLAG_EXTERNAL_PHY, b44_readphy() leaves bmcr value uninitialized and it is used later in the code.

Add check of this flag at the beginning of the b44_nway_reset() and exit early of the function if an external PHY is used, that would also correspond to other b44_readphy() call sites.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes 753f492093da ("[B44]: port to native ssb support")

Andrew

#2 lore raw
In reply to Alexey Simakov

Hi,

Quoted 20 lines · Alexey Simakov

On execution path with raised B44_FLAG_EXTERNAL_PHY, b44_readphy() leaves bmcr value uninitialized and it is used later in the code.

Add check of this flag at the beginning of the b44_nway_reset() and exit early of the function if an external PHY is used, that would also correspond to other b44_readphy() call sites.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes 753f492093da ("[B44]: port to native ssb support")
---
 drivers/net/ethernet/broadcom/b44.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/b44.c +0 -0
index 0353359c3fe9..cbfd65881326 100644

drivers/net/ethernet/broadcom/b44.c static int b44_nway_reset(struct net_device *dev) · line 1793

Quoted 5 lines
drivers/net/ethernet/broadcom/b44.c +2 -0
@@ -1789,6 +1789,9 @@ static int b44_nway_reset(struct net_device *dev)
 	u32 bmcr;
 	int r;
 
+	if (bp->flags & B44_FLAG_EXTERNAL_PHY)
+		return 0;

Wouldn't the right fix here to call phy_ethtool_nway_reset(dev->phydev); instead of just returning 0? That way it properly restarts auto-negotiation even in this case.

drivers/net/ethernet/broadcom/b44.c static int b44_nway_reset(struct net_device *dev) · line 1797

Quoted 4 lines
drivers/net/ethernet/broadcom/b44.c +1 -0
+
 	spin_lock_irq(&bp->lock);
 	b44_readphy(bp, MII_BMCR, &bmcr);
 	b44_readphy(bp, MII_BMCR, &bmcr);

Best regards,
Jonas

#3 lore raw
Quoted 11 lines

drivers/net/ethernet/broadcom/b44.c static int b44_nway_reset(struct net_device *dev) · line 1793

Quoted 7 lines

+++ b/drivers/net/ethernet/broadcom/b44.c

drivers/net/ethernet/broadcom/b44.c +2 -0
@@ -1789,6 +1789,9 @@ static int b44_nway_reset(struct net_device *dev)
 	u32 bmcr;
 	int r;
 
+	if (bp->flags & B44_FLAG_EXTERNAL_PHY)
+		return 0;

Wouldn't the right fix here to call phy_ethtool_nway_reset(dev->phydev); instead of just returning 0? That way it properly restarts auto-negotiation even in this case.

Actually, yes. ksettings_set() etc do exactly that. Let me change my Reviewed by into a Change Request.

Thanks
Andrew

---
pw-bot: cr