linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH net-next v2 6/8] net: usb: asix: add error handling for asix_mdio_* functions
Date: Mon,  7 Jun 2021 10:27:25 +0200	[thread overview]
Message-ID: <20210607082727.26045-7-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20210607082727.26045-1-o.rempel@pengutronix.de>

This usb devices can be removed at any time, so we need to forward
correct error value if device was detached.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/usb/asix_common.c | 42 +++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index 085bc8281082..ac92bc52a85e 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -485,18 +485,23 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
 		return ret;
 	}
 
-	asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
-				(__u16)loc, 2, &res, 0);
-	asix_set_hw_mii(dev, 0);
+	ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2,
+			    &res, 0);
+	if (ret < 0)
+		goto out;
+
+	ret = asix_set_hw_mii(dev, 0);
+out:
 	mutex_unlock(&dev->phy_mutex);
 
 	netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
 			phy_id, loc, le16_to_cpu(res));
 
-	return le16_to_cpu(res);
+	return ret < 0 ? ret : le16_to_cpu(res);
 }
 
-void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
+static int __asix_mdio_write(struct net_device *netdev, int phy_id, int loc,
+			     int val)
 {
 	struct usbnet *dev = netdev_priv(netdev);
 	__le16 res = cpu_to_le16(val);
@@ -516,15 +521,25 @@ void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
 		ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
 				    0, 0, 1, &smsr, 0);
 	} while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV));
-	if (ret == -ENODEV) {
-		mutex_unlock(&dev->phy_mutex);
-		return;
-	}
 
-	asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
-		       (__u16)loc, 2, &res, 0);
-	asix_set_hw_mii(dev, 0);
+	if (ret == -ENODEV)
+		goto out;
+
+	ret = asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2,
+			     &res, 0);
+	if (ret < 0)
+		goto out;
+
+	ret = asix_set_hw_mii(dev, 0);
+out:
 	mutex_unlock(&dev->phy_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+
+void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
+{
+	__asix_mdio_write(netdev, phy_id, loc, val);
 }
 
 /* MDIO read and write wrappers for phylib */
@@ -539,8 +554,7 @@ int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
 {
 	struct usbnet *priv = bus->priv;
 
-	asix_mdio_write(priv->net, phy_id, regnum, val);
-	return 0;
+	return __asix_mdio_write(priv->net, phy_id, regnum, val);
 }
 
 int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc)
-- 
2.29.2


  parent reply	other threads:[~2021-06-07  8:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  8:27 [PATCH net-next v2 0/8] port asix ax88772 to the PHYlib Oleksij Rempel
2021-06-07  8:27 ` [PATCH net-next v2 1/8] net: usb: asix: ax88772_bind: use devm_kzalloc() instead of kzalloc() Oleksij Rempel
2021-06-07  8:27 ` [PATCH net-next v2 2/8] net: usb: asix: refactor asix_read_phy_addr() and handle errors on return Oleksij Rempel
2021-06-07  8:27 ` [PATCH net-next v2 3/8] net: usb/phy: asix: add support for ax88772A/C PHYs Oleksij Rempel
2021-06-07  8:27 ` [PATCH net-next v2 4/8] net: usb: asix: ax88772: add phylib support Oleksij Rempel
     [not found]   ` <CGME20210609095923eucas1p2e692c9a482151742d543316c91f29802@eucas1p2.samsung.com>
2021-06-09  9:59     ` Marek Szyprowski
2021-06-09 12:46       ` Oleksij Rempel
2021-06-09 13:12         ` Heiner Kallweit
2021-06-10 13:36           ` Oleksij Rempel
2021-06-10 10:31         ` Marek Szyprowski
2021-06-10 12:54       ` Jon Hunter
2021-06-10 14:22         ` Oleksij Rempel
     [not found]   ` <CGME20210618083914eucas1p240f88e7064a7bf15b68370b7506d24a9@eucas1p2.samsung.com>
2021-06-18  8:39     ` Marek Szyprowski
2021-06-18 10:13       ` Oleksij Rempel
2021-06-18 10:45         ` Marek Szyprowski
2021-06-18 10:57           ` Marek Szyprowski
2021-06-18 13:10             ` Oleksij Rempel
2021-06-18 11:04         ` Heiner Kallweit
2021-06-18 11:11           ` Marek Szyprowski
2021-06-18 13:20             ` Oleksij Rempel
2021-06-21  6:05               ` Marek Szyprowski
2021-06-23  7:06                 ` Oleksij Rempel
2021-06-28  8:27                   ` Marek Szyprowski
2021-06-07  8:27 ` [PATCH net-next v2 5/8] net: usb: asix: ax88772: add generic selftest support Oleksij Rempel
2021-06-07  8:27 ` Oleksij Rempel [this message]
2021-06-07  8:27 ` [PATCH net-next v2 7/8] net: phy: do not print dump stack if device was removed Oleksij Rempel
2021-06-07  8:27 ` [PATCH net-next v2 8/8] usbnet: run unbind() before unregister_netdev() Oleksij Rempel
2021-06-07 20:40 ` [PATCH net-next v2 0/8] port asix ax88772 to the PHYlib patchwork-bot+netdevbpf

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=20210607082727.26045-7-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).