mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Grant Grundler <grundler@chromium.org>,
	Oleksij Rempel <linux@rempel-privat.de>,
	Pavel Skripkin <paskripkin@gmail.com>,
	Lukas Wunner <lukas@wunner.de>
Cc: Anton Lundin <glance@acc.umu.se>,
	Eizan Miyamoto <eizan@chromium.org>,
	Jakub Kicinski <kuba@kernel.org>, netdev <netdev@vger.kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: asix: fix modprobe "sysfs: cannot create duplicate filename"
Date: Mon, 6 Mar 2023 19:46:49 -0800	[thread overview]
Message-ID: <84094771-7f98-0d8d-fe79-7c22e15a602d@gmail.com> (raw)
In-Reply-To: <20230307005028.2065800-1-grundler@chromium.org>



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

  reply	other threads:[~2023-03-07  3:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07  0:50 Grant Grundler
2023-03-07  3:46 ` Florian Fainelli [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84094771-7f98-0d8d-fe79-7c22e15a602d@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eizan@chromium.org \
    --cc=glance@acc.umu.se \
    --cc=grundler@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rempel-privat.de \
    --cc=lukas@wunner.de \
    --cc=netdev@vger.kernel.org \
    --cc=paskripkin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®