Skip to content

Commit

Permalink
net: sun4i: fix timeout check
Browse files Browse the repository at this point in the history
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: Emilio López <emilio@elopez.com.ar>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Emilio López authored and David S. Miller committed Jul 25, 2013
1 parent 905a6f9 commit 2bf420a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions drivers/net/phy/mdio-sun4i.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct sun4i_mdio_data {
static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{
struct sun4i_mdio_data *data = bus->priv;
unsigned long start_jiffies;
unsigned long timeout_jiffies;
int value;

/* issue the phy address and reg */
Expand All @@ -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);

/* Wait read complete */
start_jiffies = jiffies;
timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_after(start_jiffies,
start_jiffies + MDIO_TIMEOUT))
if (time_is_before_jiffies(timeout_jiffies))
return -ETIMEDOUT;
msleep(1);
}
Expand All @@ -69,18 +68,17 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
u16 value)
{
struct sun4i_mdio_data *data = bus->priv;
unsigned long start_jiffies;
unsigned long timeout_jiffies;

/* issue the phy address and reg */
writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
/* pull up the phy io line */
writel(0x1, data->membase + EMAC_MAC_MCMD_REG);

/* Wait read complete */
start_jiffies = jiffies;
timeout_jiffies = jiffies + MDIO_TIMEOUT;
while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
if (time_after(start_jiffies,
start_jiffies + MDIO_TIMEOUT))
if (time_is_before_jiffies(timeout_jiffies))
return -ETIMEDOUT;
msleep(1);
}
Expand Down

0 comments on commit 2bf420a

Please sign in to comment.