Skip to content

Commit

Permalink
drivers: net: davinci_mdio: prevent spurious timeout
Browse files Browse the repository at this point in the history
A well timed kernel preemption in the time_after() loop
in wait_for_idle() can result in a spurious timeout
error to be returned.

Fix it by using readl_poll_timeout() which takes care of
this issue.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Sekhar Nori authored and David S. Miller committed May 10, 2018
1 parent bfe1e61 commit 54472ed
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/net/ethernet/ti/davinci_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/pm_runtime.h>
#include <linux/davinci_emac.h>
#include <linux/of.h>
Expand Down Expand Up @@ -227,14 +228,14 @@ static inline int wait_for_user_access(struct davinci_mdio_data *data)
static inline int wait_for_idle(struct davinci_mdio_data *data)
{
struct davinci_mdio_regs __iomem *regs = data->regs;
unsigned long timeout = jiffies + msecs_to_jiffies(MDIO_TIMEOUT);
u32 val, ret;

while (time_after(timeout, jiffies)) {
if (__raw_readl(&regs->control) & CONTROL_IDLE)
return 0;
}
dev_err(data->dev, "timed out waiting for idle\n");
return -ETIMEDOUT;
ret = readl_poll_timeout(&regs->control, val, val & CONTROL_IDLE,
0, MDIO_TIMEOUT * 1000);
if (ret)
dev_err(data->dev, "timed out waiting for idle\n");

return ret;
}

static int davinci_mdio_read(struct mii_bus *bus, int phy_id, int phy_reg)
Expand Down

0 comments on commit 54472ed

Please sign in to comment.