mtd: spi-nor: improve wait-till-ready timeout loop
There are a few small issues with the timeout loop in spi_nor_wait_till_ready(): * The first operation should not be a reschedule; we should check the status register at least once to see if we're complete! * We should check the status register one last time after declaring the deadline has passed, to prevent a premature timeout error (this is theoretically possible if we sleep for a long time after the previous status register check). * Add an error message, so it's obvious if we ever hit a timeout. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Acked-by: Huang Shijie <shijie.huang@intel.com> Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
This commit is contained in:
parent
05a221bb1f
commit
a95ce92e4b
1 changed files with 9 additions and 4 deletions
|
@ -202,19 +202,24 @@ static int spi_nor_ready(struct spi_nor *nor)
|
||||||
static int spi_nor_wait_till_ready(struct spi_nor *nor)
|
static int spi_nor_wait_till_ready(struct spi_nor *nor)
|
||||||
{
|
{
|
||||||
unsigned long deadline;
|
unsigned long deadline;
|
||||||
int ret;
|
int timeout = 0, ret;
|
||||||
|
|
||||||
deadline = jiffies + MAX_READY_WAIT_JIFFIES;
|
deadline = jiffies + MAX_READY_WAIT_JIFFIES;
|
||||||
|
|
||||||
do {
|
while (!timeout) {
|
||||||
cond_resched();
|
if (time_after_eq(jiffies, deadline))
|
||||||
|
timeout = 1;
|
||||||
|
|
||||||
ret = spi_nor_ready(nor);
|
ret = spi_nor_ready(nor);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
if (ret)
|
if (ret)
|
||||||
return 0;
|
return 0;
|
||||||
} while (!time_after_eq(jiffies, deadline));
|
|
||||||
|
cond_resched();
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_err(nor->dev, "flash operation timed out\n");
|
||||||
|
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue