| From 717fa6516e96691d2f8c1d0db60ee12e0031f36e Mon Sep 17 00:00:00 2001 |
| From: Andrew Lunn <andrew@lunn.ch> |
| Date: Thu, 17 Oct 2019 21:29:26 +0200 |
| Subject: [PATCH] net: usb: lan78xx: Connect PHY before registering MAC |
| |
| commit 38b4fe320119859c11b1dc06f6b4987a16344fa1 upstream. |
| |
| 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") |
| Reported-by: Daniel Wagner <dwagner@suse.de> |
| Signed-off-by: Andrew Lunn <andrew@lunn.ch> |
| Tested-by: Daniel Wagner <dwagner@suse.de> |
| Signed-off-by: David S. Miller <davem@davemloft.net> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c |
| index dd9b3f4c4561..7dd6289b1ffc 100644 |
| --- a/drivers/net/usb/lan78xx.c |
| +++ b/drivers/net/usb/lan78xx.c |
| @@ -3792,10 +3792,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); |
| @@ -3808,14 +3812,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: |
| -- |
| 2.7.4 |
| |