Skip to contentSkip to conversation

2.4.27 - MTD cfi_cmdset_0002.c - Duplicate cleanup in error path

PATCH In review bradgoodman.com 3 participants 4 messages Jul 23, 2004 – Aug 19, 2004 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4.27 - MTD cfi_cmdset_0002.c - Duplicate cleanup in error path

Patch to 2.4.x: Corrects an obvious error where all of the cleanups are done twice in the event of a chip programming error. This can result in kernel BUG() getting called on subsequent programming attempts.

drivers/mtd/chips/cfi_cmdset_0002.new renamed from drivers/mtd/chips/cfi_cmdset_0002.c +0 -5
@@ -549,11 +549,6 @@
 			}
 		} else {
 			printk(KERN_WARNING "Waiting for write to complete timed out in do_write_oneword.");        
-			
-			chip->state = FL_READY;
-			wake_up(&chip->wq);
-			cfi_spin_unlock(chip->mutex);
-			DISABLE_VPP(map);
 			ret = -EIO;
 		}
 	}
#1 lore raw
Quoted 9 lines · bradgoodman.com

Patch to 2.4.x: Corrects an obvious error where all of the cleanups are done twice in the event of a chip programming error. This can result in kernel BUG() getting called on subsequent programming attempts.

drivers/mtd/chips/cfi_cmdset_0002.new renamed from drivers/mtd/chips/cfi_cmdset_0002.c +0 -0
@@ -549,11 +549,6 @@
 			}

drivers/mtd/chips/cfi_cmdset_0002.new line 554

Quoted 10 lines
drivers/mtd/chips/cfi_cmdset_0002.new renamed from drivers/mtd/chips/cfi_cmdset_0002.c +0 -5
 		} else {
 			printk(KERN_WARNING "Waiting for write to complete timed out in do_write_oneword.");        
-			
-			chip->state = FL_READY;
-			wake_up(&chip->wq);
-			cfi_spin_unlock(chip->mutex);
-			DISABLE_VPP(map);
 			ret = -EIO;
 		}
 	}

I suggest the following instead:

--------------------------

cfi_cmdset_0002.c renamed from cfi_cmdset_0002.c.orig +2 -3
@@ -461,7 +461,6 @@
 	unsigned int dq6, dq5;	
 	struct cfi_private *cfi = map->fldrv_priv;
 	DECLARE_WAITQUEUE(wait, current);
-	int ret = 0;
 
  retry:
 	cfi_spin_lock(chip->mutex);
@@ -554,7 +553,7 @@
 			wake_up(&chip->wq);
 			cfi_spin_unlock(chip->mutex);
 			DISABLE_VPP(map);
-			ret = -EIO;
+			return -EIO;
 		}
 	}
 
@@ -563,7 +562,7 @@
 	wake_up(&chip->wq);
 	cfi_spin_unlock(chip->mutex);
 
-	return ret;
+	return 0;
 }
 
 static int cfi_amdstd_write (struct mtd_info *mtd, loff_t to , size_t len, size_t *retlen, const u_char *buf)

----------------------------

That way, it is consistent with the other low-level chip access functions. But the algorithm is per se buggy, anyway, because except if DQ5 was raised before, the chip is not 'ready' (for reading array data), but still in programming mode and will remain there until the 'embedded programming algorithm' stops, because (according to the docs) a reset command will not be accepted until DQ5 has been raised and the opportunityto check for that is gone after the syscall returned to the caller.

#2 lore raw

Applied Rainer's patch, its equivalent and I his "consisteny with other algorithms" point is a good one.

Thanks guys!

Quoted 4 lines · Rainer Weikusat
Quoted 3 lines · bradgoodman.com

Patch to 2.4.x: Corrects an obvious error where all of the cleanups are done twice in the event of a chip programming error. This can result in kernel BUG() getting called on subsequent programming attempts.

<snip>

Quoted 8 lines

That way, it is consistent with the other low-level chip access functions. But the algorithm is per se buggy, anyway, because except if DQ5 was raised before, the chip is not 'ready' (for reading array data), but still in programming mode and will remain there until the 'embedded programming algorithm' stops, because (according to the docs) a reset command will not be accepted until DQ5 has been raised and the opportunityto check for that is gone after the syscall returned to the caller.

#3 lore raw

I noticed it in the 2.4.28-pre1 changelog.

I had concidered doing it has he described - I figured though as a first-time submitter, the less I touched, the more comfortable people would feel with it ;-)

Thanks,

-BKG

Quoted 21 lines

Applied Rainer's patch, its equivalent and I his "consisteny with other algorithms" point is a good one.

Thanks guys!

Quoted 5 lines · Rainer Weikusat
Quoted 1 line · bradgoodman.com

Patch to 2.4.x: Corrects an obvious error where all of the cleanups

are done twice in the event of a chip programming error. This can result in kernel BUG() getting called on subsequent programming attempts.

<snip>

Quoted 8 lines

That way, it is consistent with the other low-level chip access functions. But the algorithm is per se buggy, anyway, because except if DQ5 was raised before, the chip is not 'ready' (for reading array data), but still in programming mode and will remain there until the 'embedded programming algorithm' stops, because (according to the docs) a reset command will not be accepted until DQ5 has been raised and the opportunityto check for that is gone after the syscall returned to the caller.