mtd: spi-nor: improve wait-till-ready timeout loop
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Mon Dec 15 19:59:08 PST 2014
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=a95ce92e4b289228c51114dd19f714388093d52b
Commit: a95ce92e4b289228c51114dd19f714388093d52b
Parent: 05a221bb1f49e6eebc9a3858cb45506f403b3ab6
Author: Brian Norris <computersforpeace at gmail.com>
AuthorDate: Wed Nov 5 02:32:03 2014 -0800
Committer: Brian Norris <computersforpeace at gmail.com>
CommitDate: Tue Nov 25 22:51:23 2014 -0800
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 at gmail.com>
Acked-by: Huang Shijie <shijie.huang at intel.com>
Reviewed-by: Ezequiel Garcia <ezequiel at vanguardiasur.com.ar>
---
drivers/mtd/spi-nor/spi-nor.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index eafaeeb..2bda622 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -202,19 +202,24 @@ static int spi_nor_ready(struct spi_nor *nor)
static int spi_nor_wait_till_ready(struct spi_nor *nor)
{
unsigned long deadline;
- int ret;
+ int timeout = 0, ret;
deadline = jiffies + MAX_READY_WAIT_JIFFIES;
- do {
- cond_resched();
+ while (!timeout) {
+ if (time_after_eq(jiffies, deadline))
+ timeout = 1;
ret = spi_nor_ready(nor);
if (ret < 0)
return ret;
if (ret)
return 0;
- } while (!time_after_eq(jiffies, deadline));
+
+ cond_resched();
+ }
+
+ dev_err(nor->dev, "flash operation timed out\n");
return -ETIMEDOUT;
}
More information about the linux-mtd-cvs
mailing list