Commit 2bf420a7 authored by Emilio López's avatar Emilio López Committed by David S. Miller

net: sun4i: fix timeout check

The current timeout check is comparing two constant values, so it won't
ever detect a timeout. This patch reworks the affected code a bit so it
has a chance at detecting timeouts correctly.
Signed-off-by: default avatarEmilio López <emilio@elopez.com.ar>
Acked-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 905a6f96
...@@ -40,7 +40,7 @@ struct sun4i_mdio_data { ...@@ -40,7 +40,7 @@ struct sun4i_mdio_data {
static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum) static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{ {
struct sun4i_mdio_data *data = bus->priv; struct sun4i_mdio_data *data = bus->priv;
unsigned long start_jiffies; unsigned long timeout_jiffies;
int value; int value;
/* issue the phy address and reg */ /* issue the phy address and reg */
...@@ -49,10 +49,9 @@ static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum) ...@@ -49,10 +49,9 @@ static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
writel(0x1, data->membase + EMAC_MAC_MCMD_REG); writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
/* Wait read complete */ /* Wait read complete */
start_jiffies = jiffies; timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) { while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_after(start_jiffies, if (time_is_before_jiffies(timeout_jiffies))
start_jiffies + MDIO_TIMEOUT))
return -ETIMEDOUT; return -ETIMEDOUT;
msleep(1); msleep(1);
} }
...@@ -69,7 +68,7 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum, ...@@ -69,7 +68,7 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
u16 value) u16 value)
{ {
struct sun4i_mdio_data *data = bus->priv; struct sun4i_mdio_data *data = bus->priv;
unsigned long start_jiffies; unsigned long timeout_jiffies;
/* issue the phy address and reg */ /* issue the phy address and reg */
writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG); writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
...@@ -77,10 +76,9 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum, ...@@ -77,10 +76,9 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
writel(0x1, data->membase + EMAC_MAC_MCMD_REG); writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
/* Wait read complete */ /* Wait read complete */
start_jiffies = jiffies; timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) { while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_after(start_jiffies, if (time_is_before_jiffies(timeout_jiffies))
start_jiffies + MDIO_TIMEOUT))
return -ETIMEDOUT; return -ETIMEDOUT;
msleep(1); msleep(1);
} }
......
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