Skip to contentSkip to conversation

net: xgene: fix maybe-uninitialized variable

PATCH Applied Arnd Bergmann 2 participants 2 messages Aug 2, 2016 – Aug 3, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: xgene: fix maybe-uninitialized variable

Building with -Wmaybe-uninitialized shows a potential use of an uninitialized variable:

drivers/net/ethernet/apm/xgene/xgene_enet_hw.c: In function 'xgene_enet_phy_connect':
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c:802:23: warning: 'phy_dev' may be used uninitialized in this function [-Wmaybe-uninitialized]

Although the compiler correctly identified this based on the function, the current code is still safe as long dev->of_node is non-NULL for the case of CONFIG_ACPI=n, which is currently the case.

The warning is now disabled by default, but still appears when building with W=1, and other build test tools should be able to detect it as well. Adding an #else clause here makes the code more robust and makes it clear to the compiler that this cannot happen.

Fixes 8089a96f601b ("drivers: net: xgene: Add backward compatibility")
---
 drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +2 -0
index 7714b7d4026a..98779fe2d558 100644
@@ -792,6 +792,8 @@ int xgene_enet_phy_connect(struct net_device *ndev)
 			netdev_err(ndev, "Could not connect to PHY\n");
 			return  -ENODEV;
 		}
+#else
+		return -ENODEV;
 #endif
 	}
 
Signature · 1 line
2.9.0
maintainer Applied
#1 lore raw

From: Arnd Bergmann <[email protected]>
Date: Tue, 2 Aug 2016 12:23:29 +0200

Quoted 10 lines

Building with -Wmaybe-uninitialized shows a potential use of an uninitialized variable:

drivers/net/ethernet/apm/xgene/xgene_enet_hw.c: In function 'xgene_enet_phy_connect':
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c:802:23: warning: 'phy_dev' may be used uninitialized in this function [-Wmaybe-uninitialized]

Although the compiler correctly identified this based on the function, the current code is still safe as long dev->of_node is non-NULL for the case of CONFIG_ACPI=n, which is currently the case.

Quoted 8 lines

The warning is now disabled by default, but still appears when building with W=1, and other build test tools should be able to detect it as well. Adding an #else clause here makes the code more robust and makes it clear to the compiler that this cannot happen.

Fixes 8089a96f601b ("drivers: net: xgene: Add backward compatibility")

Applied.