Skip to content

Commit 8eac009

Browse files
grundlerchromiumkuba-moo
authored andcommitted
net: asix: fix modprobe "sysfs: cannot create duplicate filename"
"modprobe asix ; rmmod asix ; modprobe asix" fails with: sysfs: cannot create duplicate filename \ '/devices/virtual/mdio_bus/usb-003:004' Issue was originally reported by Anton Lundin on 2022-06-22 (link below). Chrome OS team hit the same issue in Feb, 2023 when trying to find work arounds for other issues with AX88172 devices. The use of devm_mdiobus_register() with usbnet devices results in the MDIO data being associated with the USB device. When the asix driver is unloaded, the USB device continues to exist and the corresponding "mdiobus_unregister()" is NOT called until the USB device is unplugged or unauthorized. So the next "modprobe asix" will fail because the MDIO phy sysfs attributes still exist. The 'easy' (from a design PoV) fix is to use the non-devm variants of mdiobus_* functions and explicitly manage this use in the asix_bind and asix_unbind function calls. I've not explored trying to fix usbnet initialization so devm_* stuff will work. Fixes: e532a09 ("net: usb: asix: ax88772: add phylib support") Reported-by: Anton Lundin <[email protected]> Link: https://lore.kernel.org/netdev/[email protected]/T/ Tested-by: Eizan Miyamoto <[email protected]> Signed-off-by: Grant Grundler <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 68c3e4f commit 8eac009

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

drivers/net/usb/asix_devices.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,9 @@ static int asix_resume(struct usb_interface *intf)
666666
static int ax88772_init_mdio(struct usbnet *dev)
667667
{
668668
struct asix_common_private *priv = dev->driver_priv;
669+
int ret;
669670

670-
priv->mdio = devm_mdiobus_alloc(&dev->udev->dev);
671+
priv->mdio = mdiobus_alloc();
671672
if (!priv->mdio)
672673
return -ENOMEM;
673674

@@ -679,7 +680,20 @@ static int ax88772_init_mdio(struct usbnet *dev)
679680
snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
680681
dev->udev->bus->busnum, dev->udev->devnum);
681682

682-
return devm_mdiobus_register(&dev->udev->dev, priv->mdio);
683+
ret = mdiobus_register(priv->mdio);
684+
if (ret) {
685+
netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
686+
mdiobus_free(priv->mdio);
687+
priv->mdio = NULL;
688+
}
689+
690+
return ret;
691+
}
692+
693+
static void ax88772_mdio_unregister(struct asix_common_private *priv)
694+
{
695+
mdiobus_unregister(priv->mdio);
696+
mdiobus_free(priv->mdio);
683697
}
684698

685699
static int ax88772_init_phy(struct usbnet *dev)
@@ -896,16 +910,23 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
896910

897911
ret = ax88772_init_mdio(dev);
898912
if (ret)
899-
return ret;
913+
goto mdio_err;
900914

901915
ret = ax88772_phylink_setup(dev);
902916
if (ret)
903-
return ret;
917+
goto phylink_err;
904918

905919
ret = ax88772_init_phy(dev);
906920
if (ret)
907-
phylink_destroy(priv->phylink);
921+
goto initphy_err;
908922

923+
return 0;
924+
925+
initphy_err:
926+
phylink_destroy(priv->phylink);
927+
phylink_err:
928+
ax88772_mdio_unregister(priv);
929+
mdio_err:
909930
return ret;
910931
}
911932

@@ -926,6 +947,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
926947
phylink_disconnect_phy(priv->phylink);
927948
rtnl_unlock();
928949
phylink_destroy(priv->phylink);
950+
ax88772_mdio_unregister(priv);
929951
asix_rx_fixup_common_free(dev->driver_priv);
930952
}
931953

0 commit comments

Comments
 (0)