Skip to contentSkip to conversation

net: usb: lan78xx: Connect PHY before registering MAC

PATCH In review Andrew Lunn 3 participants 3 messages Oct 17, 2019 – Oct 18, 2019

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

PATCH 1/1 net: usb: lan78xx: Connect PHY before registering MAC

As soon as the netdev is registers, the kernel can start using the interface. If the driver connects the MAC to the PHY after the netdev is registered, there is a race condition where the interface can be opened without having the PHY connected.

Change the order to close this race condition.

Fixes 92571a1aae40 ("lan78xx: Connect phy early")
---
 drivers/net/usb/lan78xx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/usb/lan78xx.c +6 -6
index 58f5a219fb65..62948098191f 100644
@@ -3782,10 +3782,14 @@ static int lan78xx_probe(struct usb_interface *intf,
 	/* driver requires remote-wakeup capability during autosuspend. */
 	intf->needs_remote_wakeup = 1;
 
+	ret = lan78xx_phy_init(dev);
+	if (ret < 0)
+		goto out4;
+
 	ret = register_netdev(netdev);
 	if (ret != 0) {
 		netif_err(dev, probe, netdev, "couldn't register the device\n");
-		goto out4;
+		goto out5;
 	}
 
 	usb_set_intfdata(intf, dev);
@@ -3798,14 +3802,10 @@ static int lan78xx_probe(struct usb_interface *intf,
 	pm_runtime_set_autosuspend_delay(&udev->dev,
 					 DEFAULT_AUTOSUSPEND_DELAY);
 
-	ret = lan78xx_phy_init(dev);
-	if (ret < 0)
-		goto out5;
-
 	return 0;
 
 out5:
-	unregister_netdev(netdev);
+	phy_disconnect(netdev->phydev);
 out4:
 	usb_free_urb(dev->urb_intr);
 out3:
Signature · 1 line
2.23.0
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andrew Lunn

As soon as the netdev is registers, the kernel can start using the interface. If the driver connects the MAC to the PHY after the netdev is registered, there is a race condition where the interface can be opened without having the PHY connected.

Change the order to close this race condition.

Fixes 92571a1aae40 ("lan78xx: Connect phy early")

Thanks for the fix!
Daniel

maintainer
#2 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Thu, 17 Oct 2019 21:29:26 +0200

Quoted 10 lines

As soon as the netdev is registers, the kernel can start using the interface. If the driver connects the MAC to the PHY after the netdev is registered, there is a race condition where the interface can be opened without having the PHY connected.

Change the order to close this race condition.

Fixes 92571a1aae40 ("lan78xx: Connect phy early")

Applied and queued up for -stable, thanks.