Skip to contentSkip to conversation

net: dsa: vsc73xxx: Fix uninitalized 'val' in vsc73xx_adjust_link

PATCH In review Danila Chernetsov 4 participants 4 messages Mar 12, 2023 – Mar 13, 2023

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

PATCH 1/1 net: dsa: vsc73xxx: Fix uninitalized 'val' in vsc73xx_adjust_link

Using uninitialized variable after calls vsc73xx_read without error checking may cause incorrect driver behavior.

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

Fixes 95711cd5f0b4 ("net: dsa: vsc73xx: Split vsc73xx driver")
---
 drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +1 -1
index ae55167ce0a6..729005d6cb7e 100644
@@ -758,7 +758,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port,
 				struct phy_device *phydev)
 {
 	struct vsc73xx *vsc = ds->priv;
-	u32 val;
+	u32 val = 0;
 
 	/* Special handling of the CPU-facing port */
 	if (port == CPU_PORT) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Danila Chernetsov

Using uninitialized variable after calls vsc73xx_read without error checking may cause incorrect driver behavior.

I wonder if it is:
a) intentional that these calls are not checked for errors
b) errors can occur in these call paths

Quoted 24 lines

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

Fixes 95711cd5f0b4 ("net: dsa: vsc73xx: Split vsc73xx driver")
---
 drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +1 -1
index ae55167ce0a6..729005d6cb7e 100644
@@ -758,7 +758,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port,
 				struct phy_device *phydev)
 {
 	struct vsc73xx *vsc = ds->priv;
-	u32 val;
+	u32 val = 0;
 
 	/* Special handling of the CPU-facing port */
 	if (port == CPU_PORT) {
Signature · 1 line
2.25.1
maintainer
#2 lore raw
Quoted 7 lines · On Mon, 13 Mar 2023 19:59:27 +0100 Simon Horman wrote:
Quoted 2 lines · Danila Chernetsov

Using uninitialized variable after calls vsc73xx_read without error checking may cause incorrect driver behavior.

I wonder if it is:
a) intentional that these calls are not checked for errors
b) errors can occur in these call paths

At the very least we should handle the error rather than silencing the static checker complain by picking a semi-random init value for the entire function.

maintainer
#3 lore raw
In reply to Simon Horman
Quoted 6 lines · Simon Horman
Quoted 2 lines · Danila Chernetsov

Using uninitialized variable after calls vsc73xx_read without error checking may cause incorrect driver behavior.

I wonder if it is:
a) intentional that these calls are not checked for errors

probably no; this is precisely the only vsc73xx_read() call whose return code is ignores. I'd say it partly has to do with the fact that vsc73xx_adjust_link() returns void, so the author was thinking there'd be no point in checking for errors, but there clearly is

Quoted 1 line

b) errors can occur in these call paths

probably yes; one of the instantiations of vsc73xx is over SPI, where the controller can time out, etc.