Patchwork nand wait timeout fix

login
register
mail settings
Submitter Matthieu CASTET
Date Nov. 3, 2010, 11:38 a.m.
Message ID <4CD149D2.5080900@parrot.com>
Download mbox | patch
Permalink /patch/69974/
State New
Headers show

Comments

Matthieu CASTET - Nov. 3, 2010, 11:38 a.m.
nand_wait_ready timeout should not depends of HZ value.
panic_nand_wait take an relative timeout, not a absolute one.
warn if nand_wait exit while the nand is still busy.

Signed-off-by: Matthieu CASTET <matthieu.castet@parrot.com>
Artem Bityutskiy - Nov. 13, 2010, 12:13 p.m.
Matthieu,

On Wed, 2010-11-03 at 12:38 +0100, Matthieu CASTET wrote:
> nand_wait_ready timeout should not depends of HZ value.
> panic_nand_wait take an relative timeout, not a absolute one.
> warn if nand_wait exit while the nand is still busy.
> 
> Signed-off-by: Matthieu CASTET <matthieu.castet@parrot.com>

could you please improve commit message so that it would explain why you
do each of the changes, which problem you solve?

...

> @@ -874,7 +874,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
>  		chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
>  
>  	if (in_interrupt() || oops_in_progress)
> -		panic_nand_wait(mtd, chip, timeo);
> +		panic_nand_wait(mtd, chip, 400);
>  	else {
>  		while (time_before(jiffies, timeo)) {
>  			if (chip->dev_ready) {

In this cas timeo variable and its calculation can be moved to this
inner block, I suppose?

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 12e4b72..07289c0 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -519,7 +519,7 @@  static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
 void nand_wait_ready(struct mtd_info *mtd)
 {
 	struct nand_chip *chip = mtd->priv;
-	unsigned long timeo = jiffies + 2;
+	unsigned long timeo = jiffies + (2 * HZ) / 1000;
 
 	/* 400ms timeout */
 	if (in_interrupt() || oops_in_progress)
@@ -874,7 +874,7 @@  static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 		chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
 
 	if (in_interrupt() || oops_in_progress)
-		panic_nand_wait(mtd, chip, timeo);
+		panic_nand_wait(mtd, chip, 400);
 	else {
 		while (time_before(jiffies, timeo)) {
 			if (chip->dev_ready) {
@@ -890,6 +890,8 @@  static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 	led_trigger_event(nand_led_trigger, LED_OFF);
 
 	status = (int)chip->read_byte(mtd);
+	/* This can happen if in case of timeout or buggy dev_ready */
+	WARN_ON(!(status & NAND_STATUS_READY));
 	return status;
 }