Skip to contentSkip to conversation

net: phy: phylink: fix uninitialized variable in phylink_get_mac_state

PATCH Superseded Heiner Kallweit 2 participants 3 messages Feb 26, 2019

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH v2 1/1 net: phy: phylink: fix uninitialized variable in phylink_get_mac_state

When debugging an issue I found implausible values in state->pause. Reason in that state->pause isn't initialized and later only single bits are changed. Also the struct itself isn't initialized in phylink_resolve(). So better initialize state->pause.

v2:
- use right function name in subject

Fixes 9525ae83959b ("phylink: add phylink infrastructure")
---
 drivers/net/phy/phylink.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phylink.c +1 -0
index 59d175a5b..a9954c205 100644
@@ -324,6 +324,7 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state *
 	linkmode_zero(state->lp_advertising);
 	state->interface = pl->link_config.interface;
 	state->an_enabled = pl->link_config.an_enabled;
+	state->pause = MLO_PAUSE_NONE;
 	state->link = 1;
 
 	return pl->ops->mac_link_state(ndev, state);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · Heiner Kallweit

When debugging an issue I found implausible values in state->pause. Reason in that state->pause isn't initialized and later only single bits are changed. Also the struct itself isn't initialized in phylink_resolve(). So better initialize state->pause.

mac_link_state() is expected to always set this, but this is safer.

Maybe also set state->speed to SPEED_UNKNOWN, state->duplex to DUPLEX_UNKNOWN and state->an_complete to zero?

Quoted 26 lines

v2:
- use right function name in subject

Fixes 9525ae83959b ("phylink: add phylink infrastructure")
---
 drivers/net/phy/phylink.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phylink.c +1 -0
index 59d175a5b..a9954c205 100644
@@ -324,6 +324,7 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state *
 	linkmode_zero(state->lp_advertising);
 	state->interface = pl->link_config.interface;
 	state->an_enabled = pl->link_config.an_enabled;
+	state->pause = MLO_PAUSE_NONE;
 	state->link = 1;
 
 	return pl->ops->mac_link_state(ndev, state);
Signature · 1 line
2.20.1
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author maintainer
#2 lore raw
Quoted 8 lines · Russell King - ARM Linux admin
Quoted 4 lines · Heiner Kallweit

When debugging an issue I found implausible values in state->pause. Reason in that state->pause isn't initialized and later only single bits are changed. Also the struct itself isn't initialized in phylink_resolve(). So better initialize state->pause.

mac_link_state() is expected to always set this, but this is safer.

I've seen cases where mac_link_state() just initializes the relevant bits. Therefore there's no functional problem, but it's not nice (and disturbs in debug output) if all other bits have a random value.

Quoted 3 lines

Maybe also set state->speed to SPEED_UNKNOWN, state->duplex to DUPLEX_UNKNOWN and state->an_complete to zero?

OK. Will include this in a v3.

Quoted 27 lines
Quoted 26 lines

v2:
- use right function name in subject

Fixes 9525ae83959b ("phylink: add phylink infrastructure")
---
 drivers/net/phy/phylink.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/phy/phylink.c +1 -0
index 59d175a5b..a9954c205 100644
@@ -324,6 +324,7 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state *
 	linkmode_zero(state->lp_advertising);
 	state->interface = pl->link_config.interface;
 	state->an_enabled = pl->link_config.an_enabled;
+	state->pause = MLO_PAUSE_NONE;
 	state->link = 1;
 
 	return pl->ops->mac_link_state(ndev, state);
Signature · 1 line
2.20.1