aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2014-11-05 05:32:03 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-11-26 01:51:23 -0500
commita95ce92e4b289228c51114dd19f714388093d52b (patch)
tree0664ac89d17322f75a025c2d4d7da67893b73880
parent05a221bb1f49e6eebc9a3858cb45506f403b3ab6 (diff)
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>
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index eafaeeb2e580..2bda622d4621 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)
202static int spi_nor_wait_till_ready(struct spi_nor *nor) 202static int spi_nor_wait_till_ready(struct spi_nor *nor)
203{ 203{
204 unsigned long deadline; 204 unsigned long deadline;
205 int ret; 205 int timeout = 0, ret;
206 206
207 deadline = jiffies + MAX_READY_WAIT_JIFFIES; 207 deadline = jiffies + MAX_READY_WAIT_JIFFIES;
208 208
209 do { 209 while (!timeout) {
210 cond_resched(); 210 if (time_after_eq(jiffies, deadline))
211 timeout = 1;
211 212
212 ret = spi_nor_ready(nor); 213 ret = spi_nor_ready(nor);
213 if (ret < 0) 214 if (ret < 0)
214 return ret; 215 return ret;
215 if (ret) 216 if (ret)
216 return 0; 217 return 0;
217 } while (!time_after_eq(jiffies, deadline)); 218
219 cond_resched();
220 }
221
222 dev_err(nor->dev, "flash operation timed out\n");
218 223
219 return -ETIMEDOUT; 224 return -ETIMEDOUT;
220} 225}