mtd: docg4: fix status polling loop

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed Nov 13 13:59:04 EST 2013


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=9fee840c03d944ed1564c127375a702e242d9555
Commit:     9fee840c03d944ed1564c127375a702e242d9555
Parent:     5422933d58c28ebc67c7425f20e85ef27b730188
Author:     Mike Dunn <mikedunn at newsguy.com>
AuthorDate: Thu Oct 10 10:25:27 2013 -0700
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Wed Nov 6 23:32:52 2013 -0800

    mtd: docg4: fix status polling loop
    
    The loop that polls the status register waiting for an operation to complete
    foolishly bases the timeout simply on the number of loop iterations that have
    ocurred.  When I increased the processor clock speed, timeouts started to appear
    for long block erasure operations.  This patch measures the timeout using
    jiffies.
    
    Signed-off-by: Mike Dunn <mikedunn at newsguy.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/docg4.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c
index 7c38b8a..bd1cb67 100644
--- a/drivers/mtd/nand/docg4.c
+++ b/drivers/mtd/nand/docg4.c
@@ -44,6 +44,7 @@
 #include <linux/mtd/nand.h>
 #include <linux/bch.h>
 #include <linux/bitrev.h>
+#include <linux/jiffies.h>
 
 /*
  * In "reliable mode" consecutive 2k pages are used in parallel (in some
@@ -269,7 +270,7 @@ static int poll_status(struct docg4_priv *doc)
 	 */
 
 	uint16_t flash_status;
-	unsigned int timeo;
+	unsigned long timeo;
 	void __iomem *docptr = doc->virtadr;
 
 	dev_dbg(doc->dev, "%s...\n", __func__);
@@ -277,22 +278,18 @@ static int poll_status(struct docg4_priv *doc)
 	/* hardware quirk requires reading twice initially */
 	flash_status = readw(docptr + DOC_FLASHCONTROL);
 
-	timeo = 1000;
+	timeo = jiffies + msecs_to_jiffies(200); /* generous timeout */
 	do {
 		cpu_relax();
 		flash_status = readb(docptr + DOC_FLASHCONTROL);
-	} while (!(flash_status & DOC_CTRL_FLASHREADY) && --timeo);
+	} while (!(flash_status & DOC_CTRL_FLASHREADY) &&
+		 time_before(jiffies, timeo));
 
-
-	if (!timeo) {
+	if (unlikely(!(flash_status & DOC_CTRL_FLASHREADY))) {
 		dev_err(doc->dev, "%s: timed out!\n", __func__);
 		return NAND_STATUS_FAIL;
 	}
 
-	if (unlikely(timeo < 50))
-		dev_warn(doc->dev, "%s: nearly timed out; %d remaining\n",
-			 __func__, timeo);
-
 	return 0;
 }
 



More information about the linux-mtd-cvs mailing list