Skip to contentSkip to conversation

net: dsa: microchip: Fix Wake-on-LAN check to not return an error

PATCH Superseded [email protected] 2 participants 2 messages Aug 2, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: microchip: Fix Wake-on-LAN check to not return an error

From: Tristram Ha <[email protected]>

The wol variable in ksz_port_set_mac_address() is declared with random data, but the code in ksz_get_wol call may not be executed so the WAKE_MAGIC check may be invalid resulting in an error message when setting a MAC address after starting the DSA driver.

Fixes 3b454b6390c3 ("net: dsa: microchip: ksz9477: Add Wake on Magic Packet support")
---
 drivers/net/dsa/microchip/ksz_common.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/dsa/microchip/ksz_common.c +6 -0
index b074b4bb0629..2725c5bc311c 100644
@@ -3764,6 +3764,12 @@ static int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
 		return -EBUSY;
 	}
 
+	/* Need to initialize variable as the code to fill in settings may
+	 * not be executed.
+	 */
+	wol.supported = 0;
+	wol.wolopts = 0;
+
 	ksz_get_wol(ds, dp->index, &wol);
 	if (wol.wolopts & WAKE_MAGIC) {
 		dev_err(ds->dev,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · On Thu, Aug 01, 2024 at 05:05:10PM -0700, [email protected] wrote:

From: Tristram Ha <[email protected]>

The wol variable in ksz_port_set_mac_address() is declared with random data, but the code in ksz_get_wol call may not be executed so the WAKE_MAGIC check may be invalid resulting in an error message when setting a MAC address after starting the DSA driver.

Fixes 3b454b6390c3 ("net: dsa: microchip: ksz9477: Add Wake on Magic Packet support")
---
 drivers/net/dsa/microchip/ksz_common.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/dsa/microchip/ksz_common.c +0 -0
index b074b4bb0629..2725c5bc311c 100644
@@ -3764,6 +3764,12 @@ static int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
 		return -EBUSY;
 	}

drivers/net/dsa/microchip/ksz_common.c static int ksz_port_set_mac_address(struct dsa_switch *ds, int port, · line 3775

Quoted 10 lines
drivers/net/dsa/microchip/ksz_common.c +6 -0
 
+	/* Need to initialize variable as the code to fill in settings may
+	 * not be executed.
+	 */
+	wol.supported = 0;
+	wol.wolopts = 0;
+
 	ksz_get_wol(ds, dp->index, &wol);
 	if (wol.wolopts & WAKE_MAGIC) {
 		dev_err(ds->dev,

Only wol.wolopts need to be cleared. wol.supported can be dropped.

With this change:

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |