linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
@ 2023-03-07  0:50 Grant Grundler
  2023-03-07  3:46 ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: Grant Grundler @ 2023-03-07  0:50 UTC (permalink / raw)
  To: Oleksij Rempel, Pavel Skripkin, Lukas Wunner
  Cc: Anton Lundin, Eizan Miyamoto, Jakub Kicinski, netdev,
	David S . Miller, LKML, Grant Grundler

"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 14:16 UTC:
   https://lore.kernel.org/netdev/20220623063649.GD23685@pengutronix.de/T/

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.

Reported-by: Anton Lundin <glance@acc.umu.se>
Tested-by: Eizan Miyamoto <eizan@chromium.org>
Signed-off-by: Grant Grundler <grundler@chromium.org>
---
 drivers/net/usb/asix_devices.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 30e87389aefa1..f0a87b933062a 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -640,8 +640,9 @@ static int asix_resume(struct usb_interface *intf)
 static int ax88772_init_mdio(struct usbnet *dev)
 {
 	struct asix_common_private *priv = dev->driver_priv;
+	int ret;
 
-	priv->mdio = devm_mdiobus_alloc(&dev->udev->dev);
+	priv->mdio = mdiobus_alloc();
 	if (!priv->mdio)
 		return -ENOMEM;
 
@@ -653,7 +654,27 @@ static int ax88772_init_mdio(struct usbnet *dev)
 	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
 		 dev->udev->bus->busnum, dev->udev->devnum);
 
-	return devm_mdiobus_register(&dev->udev->dev, priv->mdio);
+	ret = mdiobus_register(priv->mdio);
+	if (ret) {
+		netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
+		goto mdio_regerr;
+	}
+
+	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
+	if (priv->phydev)
+		return 0;
+
+	netdev_err(dev->net, "Could not find PHY\n");
+	mdiobus_unregister(priv->mdio);
+mdio_regerr:
+	mdiobus_free(priv->mdio);
+	return ret;
+}
+
+static void ax88772_release_mdio(struct asix_common_private *priv)
+{
+	mdiobus_unregister(priv->mdio);
+	mdiobus_free(priv->mdio);
 }
 
 static int ax88772_init_phy(struct usbnet *dev)
@@ -661,12 +682,6 @@ static int ax88772_init_phy(struct usbnet *dev)
 	struct asix_common_private *priv = dev->driver_priv;
 	int ret;
 
-	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
-	if (!priv->phydev) {
-		netdev_err(dev->net, "Could not find PHY\n");
-		return -ENODEV;
-	}
-
 	ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
 				 PHY_INTERFACE_MODE_INTERNAL);
 	if (ret) {
@@ -805,6 +820,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
 	struct asix_common_private *priv = dev->driver_priv;
 
 	phy_disconnect(priv->phydev);
+	ax88772_release_mdio(priv);
 	asix_rx_fixup_common_free(dev->driver_priv);
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
  2023-03-07  0:50 [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename" Grant Grundler
@ 2023-03-07  3:46 ` Florian Fainelli
  2023-03-07  6:22   ` Grant Grundler
       [not found]   ` <CANEJEGvM_xLrSSjrgKLh_xP+BrFFT+afDQhG8BOdgHPf7eR4gQ@mail.gmail.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Florian Fainelli @ 2023-03-07  3:46 UTC (permalink / raw)
  To: Grant Grundler, Oleksij Rempel, Pavel Skripkin, Lukas Wunner
  Cc: Anton Lundin, Eizan Miyamoto, Jakub Kicinski, netdev,
	David S . Miller, LKML



On 3/6/2023 4:50 PM, Grant Grundler wrote:
> "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 14:16 UTC:
>     https://lore.kernel.org/netdev/20220623063649.GD23685@pengutronix.de/T/
> 
> 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.
> 
> Reported-by: Anton Lundin <glance@acc.umu.se>
> Tested-by: Eizan Miyamoto <eizan@chromium.org>
> Signed-off-by: Grant Grundler <grundler@chromium.org>

Should we have a Fixes: tag here? One more question below

> ---
>   drivers/net/usb/asix_devices.c | 32 ++++++++++++++++++++++++--------
>   1 file changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index 30e87389aefa1..f0a87b933062a 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -640,8 +640,9 @@ static int asix_resume(struct usb_interface *intf)
>   static int ax88772_init_mdio(struct usbnet *dev)
>   {
>   	struct asix_common_private *priv = dev->driver_priv;
> +	int ret;
>   
> -	priv->mdio = devm_mdiobus_alloc(&dev->udev->dev);
> +	priv->mdio = mdiobus_alloc();
>   	if (!priv->mdio)
>   		return -ENOMEM;
>   
> @@ -653,7 +654,27 @@ static int ax88772_init_mdio(struct usbnet *dev)
>   	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
>   		 dev->udev->bus->busnum, dev->udev->devnum);
>   
> -	return devm_mdiobus_register(&dev->udev->dev, priv->mdio);
> +	ret = mdiobus_register(priv->mdio);
> +	if (ret) {
> +		netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
> +		goto mdio_regerr;
> +	}
> +
> +	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> +	if (priv->phydev)
> +		return 0;

This was in ax88772_init_phy() before, why is this being moved here now?

> +
> +	netdev_err(dev->net, "Could not find PHY\n");
> +	mdiobus_unregister(priv->mdio);
> +mdio_regerr:
> +	mdiobus_free(priv->mdio);
> +	return ret;
> +}
> +
> +static void ax88772_release_mdio(struct asix_common_private *priv)
> +{
> +	mdiobus_unregister(priv->mdio);
> +	mdiobus_free(priv->mdio);
>   }
>   
>   static int ax88772_init_phy(struct usbnet *dev)
> @@ -661,12 +682,6 @@ static int ax88772_init_phy(struct usbnet *dev)
>   	struct asix_common_private *priv = dev->driver_priv;
>   	int ret;
>   
> -	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> -	if (!priv->phydev) {
> -		netdev_err(dev->net, "Could not find PHY\n");
> -		return -ENODEV;
> -	}
> -
>   	ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
>   				 PHY_INTERFACE_MODE_INTERNAL);
>   	if (ret) {
> @@ -805,6 +820,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
>   	struct asix_common_private *priv = dev->driver_priv;
>   
>   	phy_disconnect(priv->phydev);
> +	ax88772_release_mdio(priv);
>   	asix_rx_fixup_common_free(dev->driver_priv);
>   }
>   

-- 
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
  2023-03-07  3:46 ` Florian Fainelli
@ 2023-03-07  6:22   ` Grant Grundler
  2023-03-07  8:40     ` Oleksij Rempel
       [not found]   ` <CANEJEGvM_xLrSSjrgKLh_xP+BrFFT+afDQhG8BOdgHPf7eR4gQ@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Grant Grundler @ 2023-03-07  6:22 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Grant Grundler, Oleksij Rempel, Pavel Skripkin, Lukas Wunner,
	Eizan Miyamoto, Jakub Kicinski, netdev, David S . Miller, LKML

[dropping Aton Lundin <glance@...> since it's bouncing ... and
replying in "text only"]

On Mon, Mar 6, 2023 at 7:46 PM Florian Fainelli <f.fainelli@gmail.com> wrote:
>
>
>
> On 3/6/2023 4:50 PM, Grant Grundler wrote:
> > "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 14:16 UTC:
> >     https://lore.kernel.org/netdev/20220623063649.GD23685@pengutronix.de/T/
> >
> > 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.
> >
> > Reported-by: Anton Lundin <glance@acc.umu.se>
> > Tested-by: Eizan Miyamoto <eizan@chromium.org>
> > Signed-off-by: Grant Grundler <grundler@chromium.org>
>
> Should we have a Fixes: tag here? One more question below

I have no idea which change/patch caused this problem. I'm happy to
add whatever Fixes: tag folks suggest.

Looking at git blame, looks like the devm_mdiobus_* usage was
introduced with e532a096be0e5:

commit e532a096be0e5e570b383e71d4560e7f04384e0f
Author: Oleksij Rempel <linux@rempel-privat.de>
Date:   Mon Jun 7 10:27:23 2021 +0200

    net: usb: asix: ax88772: add phylib support

>
> > ---
> >   drivers/net/usb/asix_devices.c | 32 ++++++++++++++++++++++++--------
> >   1 file changed, 24 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> > index 30e87389aefa1..f0a87b933062a 100644
> > --- a/drivers/net/usb/asix_devices.c
> > +++ b/drivers/net/usb/asix_devices.c
> > @@ -640,8 +640,9 @@ static int asix_resume(struct usb_interface *intf)
> >   static int ax88772_init_mdio(struct usbnet *dev)
> >   {
> >       struct asix_common_private *priv = dev->driver_priv;
> > +     int ret;
> >
> > -     priv->mdio = devm_mdiobus_alloc(&dev->udev->dev);
> > +     priv->mdio = mdiobus_alloc();
> >       if (!priv->mdio)
> >               return -ENOMEM;
> >
> > @@ -653,7 +654,27 @@ static int ax88772_init_mdio(struct usbnet *dev)
> >       snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
> >                dev->udev->bus->busnum, dev->udev->devnum);
> >
> > -     return devm_mdiobus_register(&dev->udev->dev, priv->mdio);
> > +     ret = mdiobus_register(priv->mdio);
> > +     if (ret) {
> > +             netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
> > +             goto mdio_regerr;
> > +     }
> > +
> > +     priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> > +     if (priv->phydev)
> > +             return 0;
>
> This was in ax88772_init_phy() before, why is this being moved here now?

1) To be consistent with other drivers (e.g. tg3 and r8169) which call
 mdiobus from one function.
2) So the functions called from ax88172_bind and ax88172_unbind are
"symmetric".  I am now thinking the two functions should be renamed to
ax88172_mdio_register and ..._unregister.

Thanks for looking Florian!

cheers,
grant

>
> > +
> > +     netdev_err(dev->net, "Could not find PHY\n");
> > +     mdiobus_unregister(priv->mdio);
> > +mdio_regerr:
> > +     mdiobus_free(priv->mdio);
> > +     return ret;
> > +}
> > +
> > +static void ax88772_release_mdio(struct asix_common_private *priv)
> > +{
> > +     mdiobus_unregister(priv->mdio);
> > +     mdiobus_free(priv->mdio);
> >   }
> >
> >   static int ax88772_init_phy(struct usbnet *dev)
> > @@ -661,12 +682,6 @@ static int ax88772_init_phy(struct usbnet *dev)
> >       struct asix_common_private *priv = dev->driver_priv;
> >       int ret;
> >
> > -     priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> > -     if (!priv->phydev) {
> > -             netdev_err(dev->net, "Could not find PHY\n");
> > -             return -ENODEV;
> > -     }
> > -
> >       ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
> >                                PHY_INTERFACE_MODE_INTERNAL);
> >       if (ret) {
> > @@ -805,6 +820,7 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
> >       struct asix_common_private *priv = dev->driver_priv;
> >
> >       phy_disconnect(priv->phydev);
> > +     ax88772_release_mdio(priv);
> >       asix_rx_fixup_common_free(dev->driver_priv);
> >   }
> >
>
> --
> Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
  2023-03-07  6:22   ` Grant Grundler
@ 2023-03-07  8:40     ` Oleksij Rempel
  0 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2023-03-07  8:40 UTC (permalink / raw)
  To: Grant Grundler
  Cc: Florian Fainelli, Oleksij Rempel, Pavel Skripkin, Lukas Wunner,
	Eizan Miyamoto, Jakub Kicinski, netdev, David S . Miller, LKML

Hi Grant,

On Mon, Mar 06, 2023 at 10:22:06PM -0800, Grant Grundler wrote:
...
> [dropping Aton Lundin <glance@...> since it's bouncing ... and
> replying in "text only"]
> > Should we have a Fixes: tag here? One more question below
> 
> I have no idea which change/patch caused this problem. I'm happy to
> add whatever Fixes: tag folks suggest.
> 
> Looking at git blame, looks like the devm_mdiobus_* usage was
> introduced with e532a096be0e5:
> 
> commit e532a096be0e5e570b383e71d4560e7f04384e0f
> Author: Oleksij Rempel <linux@rempel-privat.de>
> Date:   Mon Jun 7 10:27:23 2021 +0200
> 
>     net: usb: asix: ax88772: add phylib support

Yes, this is the right commit.

Regards,
Oleksij
-- 
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 |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
       [not found]   ` <CANEJEGvM_xLrSSjrgKLh_xP+BrFFT+afDQhG8BOdgHPf7eR4gQ@mail.gmail.com>
@ 2023-03-07 10:29     ` Lukas Wunner
  2023-03-07 18:13       ` Grant Grundler
  0 siblings, 1 reply; 6+ messages in thread
From: Lukas Wunner @ 2023-03-07 10:29 UTC (permalink / raw)
  To: Grant Grundler
  Cc: Florian Fainelli, Oleksij Rempel, Pavel Skripkin, Anton Lundin,
	Eizan Miyamoto, Jakub Kicinski, netdev, David S . Miller, LKML

On Mon, Mar 06, 2023 at 10:10:09PM -0800, Grant Grundler wrote:
> On Mon, Mar 6, 2023 at 7:46???PM Florian Fainelli <f.fainelli@gmail.com> wrote:
> > On 3/6/2023 4:50 PM, Grant Grundler wrote:
> > > +     priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> > > +     if (priv->phydev)
> > > +             return 0;
> >
> > This was in ax88772_init_phy() before, why is this being moved here now?
> 
> Because other drivers I looked at (e.g. tg3 and r8169) do all the mdiobus_*
> calls in one function and I wanted to have some "symmetry"
> with ax88772_release_mdio() function I added below.

I'd suggest moving this cleanup to a separate commit so that you keep
the fix itself as small as possible and thus minimize the potential of
introducing regressions in stable kernels that will receive the fix.

Also, per convention please use the if-clause to catch the error case,
not the success case.  It doesn't matter if you need two or three more
lines, readability is more important IMO.

Thanks,

Lukas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
  2023-03-07 10:29     ` Lukas Wunner
@ 2023-03-07 18:13       ` Grant Grundler
  0 siblings, 0 replies; 6+ messages in thread
From: Grant Grundler @ 2023-03-07 18:13 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: Grant Grundler, Florian Fainelli, Oleksij Rempel, Pavel Skripkin,
	Anton Lundin, Eizan Miyamoto, Jakub Kicinski, netdev,
	David S . Miller, LKML

On Tue, Mar 7, 2023 at 2:29 AM Lukas Wunner <lukas@wunner.de> wrote:
>
> On Mon, Mar 06, 2023 at 10:10:09PM -0800, Grant Grundler wrote:
> > On Mon, Mar 6, 2023 at 7:46???PM Florian Fainelli <f.fainelli@gmail.com> wrote:
> > > On 3/6/2023 4:50 PM, Grant Grundler wrote:
> > > > +     priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> > > > +     if (priv->phydev)
> > > > +             return 0;
> > >
> > > This was in ax88772_init_phy() before, why is this being moved here now?
> >
> > Because other drivers I looked at (e.g. tg3 and r8169) do all the mdiobus_*
> > calls in one function and I wanted to have some "symmetry"
> > with ax88772_release_mdio() function I added below.
>
> I'd suggest moving this cleanup to a separate commit so that you keep
> the fix itself as small as possible and thus minimize the potential of
> introducing regressions in stable kernels that will receive the fix.

Ok - will do.

> Also, per convention please use the if-clause to catch the error case,
> not the success case.  It doesn't matter if you need two or three more
> lines, readability is more important IMO.

Sure. No problem. The code I wrote seemed easier to read but I'm
familiar with the convention and have no objection to that.

I'll add the Fixes: tag as well (thanks for confirming Oleksij!)

cheers,
grant

>
> Thanks,
>
> Lukas

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-07 18:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07  0:50 [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename" Grant Grundler
2023-03-07  3:46 ` Florian Fainelli
2023-03-07  6:22   ` Grant Grundler
2023-03-07  8:40     ` Oleksij Rempel
     [not found]   ` <CANEJEGvM_xLrSSjrgKLh_xP+BrFFT+afDQhG8BOdgHPf7eR4gQ@mail.gmail.com>
2023-03-07 10:29     ` Lukas Wunner
2023-03-07 18:13       ` Grant Grundler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).