Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
[linux-2.6-microblaze.git] / drivers / mtd / mtdblock.c
index 078e0f6..32e52d8 100644 (file)
@@ -89,8 +89,6 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
 
        ret = erase_write (mtd, mtdblk->cache_offset,
                           mtdblk->cache_size, mtdblk->cache_data);
-       if (ret)
-               return ret;
 
        /*
         * Here we could arguably set the cache state to STATE_CLEAN.
@@ -98,9 +96,14 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
         * be notified if this content is altered on the flash by other
         * means.  Let's declare it empty and leave buffering tasks to
         * the buffer cache instead.
+        *
+        * If this cache_offset points to a bad block, data cannot be
+        * written to the device. Clear cache_state to avoid writing to
+        * bad blocks repeatedly.
         */
-       mtdblk->cache_state = STATE_EMPTY;
-       return 0;
+       if (ret == 0 || ret == -EIO)
+               mtdblk->cache_state = STATE_EMPTY;
+       return ret;
 }