Skip to content

Commit

Permalink
net: usb: lan78xx: Connect PHY before registering MAC
Browse files Browse the repository at this point in the history
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: 92571a1 ("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>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Oct 18, 2019
1 parent e381d2b commit 38b4fe3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/net/usb/lan78xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down

0 comments on commit 38b4fe3

Please sign in to comment.