mtd/drivers/mtd/chips cfi_cmdset_0002.c,1.86,1.87

Thayne Harbaugh tharbaugh at lnxi.com
Fri Oct 17 16:57:16 EDT 2003


Update of /home/cvs/mtd/drivers/mtd/chips
In directory phoenix.infradead.org:/tmp/cvs-serv6638

Modified Files:
	cfi_cmdset_0002.c 
Log Message:
fix read/modify/write condition in cfi_amdstd_write() - credit to Stefano Babic

Index: cfi_cmdset_0002.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0002.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- cfi_cmdset_0002.c	17 Oct 2003 20:32:40 -0000	1.86
+++ cfi_cmdset_0002.c	17 Oct 2003 20:57:13 -0000	1.87
@@ -826,6 +826,7 @@
 	int ret = 0;
 	int chipnum;
 	unsigned long ofs, chipstart;
+	DECLARE_WAITQUEUE(wait, current);
 
 	*retlen = 0;
 	if (!len)
@@ -843,9 +844,35 @@
 		u_char tmp_buf[8];
 		cfi_word datum;
 
+ retry:
+		cfi_spin_lock(cfi->chips[chipnum].mutex);
+
+		if (cfi->chips[chipnum].state != FL_READY) {
+#if 0
+			printk(KERN_DEBUG "Waiting for chip to write, status = %d\n", cfi->chips[chipnum].state);
+#endif
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			add_wait_queue(&cfi->chips[chipnum].wq, &wait);
+
+			cfi_spin_unlock(cfi->chips[chipnum].mutex);
+
+			schedule();
+			remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
+#if 0
+			if(signal_pending(current))
+				return -EINTR;
+#endif
+			goto retry;
+		}
+
 		map_copy_from(map, tmp_buf, bus_ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH);
-		while (len && i < CFIDEV_BUSWIDTH)
-			tmp_buf[i++] = buf[n++], len--;
+
+		cfi_spin_unlock(cfi->chips[chipnum].mutex);
+
+		while (len && i < CFIDEV_BUSWIDTH) {
+			tmp_buf[i++] = buf[n++];
+                        len--;
+                }
 
 		/* already know that buswidth > 1 */
 		if (cfi_buswidth_is_2()) {
@@ -954,7 +981,31 @@
 		u_char tmp_buf[8];
 		cfi_word datum;
 
+ retry1:
+		cfi_spin_lock(cfi->chips[chipnum].mutex);
+
+		if (cfi->chips[chipnum].state != FL_READY) {
+#if 0
+			printk(KERN_DEBUG "Waiting for chip to write, status = %d\n", cfi->chips[chipnum].state);
+#endif
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			add_wait_queue(&cfi->chips[chipnum].wq, &wait);
+
+			cfi_spin_unlock(cfi->chips[chipnum].mutex);
+
+			schedule();
+			remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
+#if 0
+			if(signal_pending(current))
+				return -EINTR;
+#endif
+			goto retry1;
+		}
+
 		map_copy_from(map, tmp_buf, ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH);
+
+		cfi_spin_unlock(cfi->chips[chipnum].mutex);
+
 		while (len--)
 			tmp_buf[i++] = buf[n++];
 




More information about the linux-mtd-cvs mailing list