UBI: handle zero-length case
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Thu, 24 Jan 2008 15:56:14 +0000 (17:56 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 25 Jan 2008 14:41:25 +0000 (16:41 +0200)
ubi_eba_atomic_leb_change() has to just map the LEB to a free PEB
if data length is zero.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/eba.c

index 1f7375e..7ce91ca 100644 (file)
@@ -862,6 +862,17 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
        if (ubi->ro_mode)
                return -EROFS;
 
+       if (len == 0) {
+               /*
+                * Special case when data length is zero. In this case the LEB
+                * has to be unmapped and mapped somewhere else.
+                */
+               err = ubi_eba_unmap_leb(ubi, vol, lnum);
+               if (err)
+                       return err;
+               return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype);
+       }
+
        vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
        if (!vid_hdr)
                return -ENOMEM;