diff mbox series

[PATCHv2,2/2] net: asix: init mdiobus from one function

Message ID 20230307200502.2263655-2-grundler@chromium.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [PATCHv2,1/2] TEST:net: asix: fix modprobe "sysfs: cannot create duplicate filename" | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Grant Grundler March 7, 2023, 8:05 p.m. UTC
Make asix driver consistent with other drivers (e.g. tg3 and r8169) which
use mdiobus calls: setup and tear down be handled in one function each.

Signed-off-by: Grant Grundler <grundler@chromium.org>
---
 drivers/net/usb/asix_devices.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

Comments

Grant Grundler March 7, 2023, 8:13 p.m. UTC | #1
On Tue, Mar 7, 2023 at 12:05 PM Grant Grundler <grundler@chromium.org> wrote:
>
> Make asix driver consistent with other drivers (e.g. tg3 and r8169) which
> use mdiobus calls: setup and tear down be handled in one function each.
>
> Signed-off-by: Grant Grundler <grundler@chromium.org>
> ---
>  drivers/net/usb/asix_devices.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index 21845b88a64b9..d7caab4493d15 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -637,7 +637,7 @@ static int asix_resume(struct usb_interface *intf)
>         return usbnet_resume(intf);
>  }
>
> -static int ax88772_init_mdio(struct usbnet *dev)
> +static int ax88772_mdio_register(struct usbnet *dev)
>  {
>         struct asix_common_private *priv = dev->driver_priv;
>         int ret;
> @@ -657,10 +657,22 @@ static int ax88772_init_mdio(struct usbnet *dev)
>         ret = mdiobus_register(priv->mdio);
>         if (ret) {
>                 netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
> -               mdiobus_free(priv->mdio);
> -               priv->mdio = NULL;
> +               goto mdio_register_err;
>         }
>
> +       priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
> +       if (!priv->phydev) {
> +               netdev_err(dev->net, "Could not find PHY\n");
> +               ret=-ENODEV;

My apologies: checkpatch wants spaces around "=" and especially
because it should be "ret = -ENODEV".

I can resend - but is this trivial enough to fix up by maintainer?

cheers,
grant

> +               goto mdio_phy_err;
> +       }
> +
> +       return 0;
> +
> +mdio_phy_err:
> +       mdiobus_unregister(priv->mdio);
> +mdio_register_err:
> +       mdiobus_free(priv->mdio);
>         return ret;
>  }
>
> @@ -675,13 +687,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");
> -               ax88772_mdio_unregister(priv);
> -               return -ENODEV;
> -       }
> -
>         ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
>                                  PHY_INTERFACE_MODE_INTERNAL);
>         if (ret) {
> @@ -799,7 +804,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
>         priv->presvd_phy_bmcr = 0;
>         priv->presvd_phy_advertise = 0;
>
> -       ret = ax88772_init_mdio(dev);
> +       ret = ax88772_mdio_register(dev);
>         if (ret)
>                 return ret;
>
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 21845b88a64b9..d7caab4493d15 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -637,7 +637,7 @@  static int asix_resume(struct usb_interface *intf)
 	return usbnet_resume(intf);
 }
 
-static int ax88772_init_mdio(struct usbnet *dev)
+static int ax88772_mdio_register(struct usbnet *dev)
 {
 	struct asix_common_private *priv = dev->driver_priv;
 	int ret;
@@ -657,10 +657,22 @@  static int ax88772_init_mdio(struct usbnet *dev)
 	ret = mdiobus_register(priv->mdio);
 	if (ret) {
 		netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
-		mdiobus_free(priv->mdio);
-		priv->mdio = NULL;
+		goto mdio_register_err;
 	}
 
+	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
+	if (!priv->phydev) {
+		netdev_err(dev->net, "Could not find PHY\n");
+		ret=-ENODEV;
+		goto mdio_phy_err;
+	}
+
+	return 0;
+
+mdio_phy_err:
+	mdiobus_unregister(priv->mdio);
+mdio_register_err:
+	mdiobus_free(priv->mdio);
 	return ret;
 }
 
@@ -675,13 +687,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");
-		ax88772_mdio_unregister(priv);
-		return -ENODEV;
-	}
-
 	ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
 				 PHY_INTERFACE_MODE_INTERNAL);
 	if (ret) {
@@ -799,7 +804,7 @@  static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 	priv->presvd_phy_bmcr = 0;
 	priv->presvd_phy_advertise = 0;
 
-	ret = ax88772_init_mdio(dev);
+	ret = ax88772_mdio_register(dev);
 	if (ret)
 		return ret;