mtd/drivers/mtd mtdblock.c,1.61,1.62

joern at infradead.org joern at infradead.org
Mon Jun 2 12:29:50 EDT 2003


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

Modified Files:
	mtdblock.c 
Log Message:
defer buffer allocation until the first write.  (saves some ram)



Index: mtdblock.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtdblock.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- mtdblock.c	21 May 2003 10:49:38 -0000	1.61
+++ mtdblock.c	2 Jun 2003 16:29:47 -0000	1.62
@@ -248,6 +248,15 @@
 			      unsigned long block, char *buf)
 {
 	struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
+	if (unlikely(!mtdblk->cache_data)) {
+		mtdblk->cache_data = vmalloc(mtdblk->mtd->erasesize);
+		if (!mtdblk->cache_data)
+			return -EINTR;
+		/* -EINTR is not really correct, but it is the best match
+		 * documented in man 2 write for all cases.  We could also
+		 * return -EAGAIN sometimes, but why bother?
+		 */
+	}
 	return do_cached_write(mtdblk, block<<9, 512, buf);
 }
 
@@ -279,11 +288,7 @@
 	if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
 	    mtdblk->mtd->erasesize) {
 		mtdblk->cache_size = mtdblk->mtd->erasesize;
-		mtdblk->cache_data = vmalloc(mtdblk->mtd->erasesize);
-		if (!mtdblk->cache_data) {
-			kfree(mtdblk);
-			return -ENOMEM;
-		}
+		mtdblk->cache_data = NULL;
 	}
 
 	mtdblks[dev] = mtdblk;




More information about the linux-mtd-cvs mailing list