Commit b95f9609 authored by Konstantin Baidarov's avatar Konstantin Baidarov Committed by Thomas Gleixner

[MTD] chips cfi_cmdset_0002: Prevent timeout race

We've noticed that sometimes "MTD do_write_buffer(): software timeout"
message was printed out when writing to a Fujitsu NOR flash.
It turned out that this was because of a race in the timeout handling
do_write_buffer(). A small timeout of (HZ / 1000) + 1 is used there, and
sometimes if the timer interrupt handling takes more than one or even two
jiffies (which is 1-2 ms with HZ == 1000) and that interrupt happens just
after chip_ready() call, the driver bails out from a ready polling loop
despite the chip has actually become ready while all those interrupts were
handled. To deal with this issue, extra check for chip ready is neccessary on
timeout expiration (and the checks should better be reordered).
As do_write_oneword() uses the same approach, it needs to also be changed.
Signed-off-by: default avatarKonstantin Baidarov <kbaidarov@ru.mvista.com>
Signed-off-by: default avatarSergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent be30c10f
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* This code is GPL * This code is GPL
* *
* $Id: cfi_cmdset_0002.c,v 1.120 2005/07/20 21:01:13 tpoynor Exp $ * $Id: cfi_cmdset_0002.c,v 1.121 2005/11/07 09:00:01 gleixner Exp $
* *
*/ */
...@@ -1014,16 +1014,16 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, ...@@ -1014,16 +1014,16 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
continue; continue;
} }
if (chip_ready(map, adr)) if (time_after(jiffies, timeo) && !chip_ready(map, adr)){
break;
if (time_after(jiffies, timeo)) {
xip_enable(map, chip, adr); xip_enable(map, chip, adr);
printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
xip_disable(map, chip, adr); xip_disable(map, chip, adr);
break; break;
} }
if (chip_ready(map, adr))
break;
/* Latency issues. Drop the lock, wait a while and retry */ /* Latency issues. Drop the lock, wait a while and retry */
UDELAY(map, chip, adr, 1); UDELAY(map, chip, adr, 1);
} }
...@@ -1275,13 +1275,13 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, ...@@ -1275,13 +1275,13 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
continue; continue;
} }
if (time_after(jiffies, timeo) && !chip_ready(map, adr))
break;
if (chip_ready(map, adr)) { if (chip_ready(map, adr)) {
xip_enable(map, chip, adr); xip_enable(map, chip, adr);
goto op_done; goto op_done;
} }
if( time_after(jiffies, timeo))
break;
/* Latency issues. Drop the lock, wait a while and retry */ /* Latency issues. Drop the lock, wait a while and retry */
UDELAY(map, chip, adr, 1); UDELAY(map, chip, adr, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment