Commit d275afb6 authored by Oleksij Rempel's avatar Oleksij Rempel Committed by David S. Miller

net: usb: asix: add error handling for asix_mdio_* functions

This usb devices can be removed at any time, so we need to forward
correct error value if device was detached.
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 34a1dee6
...@@ -485,18 +485,23 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) ...@@ -485,18 +485,23 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
return ret; return ret;
} }
asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2,
(__u16)loc, 2, &res, 0); &res, 0);
asix_set_hw_mii(dev, 0); if (ret < 0)
goto out;
ret = asix_set_hw_mii(dev, 0);
out:
mutex_unlock(&dev->phy_mutex); mutex_unlock(&dev->phy_mutex);
netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", 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)); 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); struct usbnet *dev = netdev_priv(netdev);
__le16 res = cpu_to_le16(val); __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) ...@@ -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, ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
0, 0, 1, &smsr, 0); 0, 0, 1, &smsr, 0);
} while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); } 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, if (ret == -ENODEV)
(__u16)loc, 2, &res, 0); goto out;
asix_set_hw_mii(dev, 0);
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); 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 */ /* 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) ...@@ -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; struct usbnet *priv = bus->priv;
asix_mdio_write(priv->net, phy_id, regnum, val); return __asix_mdio_write(priv->net, phy_id, regnum, val);
return 0;
} }
int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc) int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment