UBI: do not let to read too much
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sat, 5 May 2007 11:59:23 +0000 (14:59 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 18 Jul 2007 13:52:42 +0000 (16:52 +0300)
In case of static volumes it is prohibited to read more data
then available.

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

index d352c4575c3da3d6f3f834116daa72062eb2bf86..14c66b48798e2f882f583dc5af38f67916000227 100644 (file)
@@ -319,9 +319,14 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
            offset + len > vol->usable_leb_size)
                return -EINVAL;
 
-       if (vol->vol_type == UBI_STATIC_VOLUME && lnum == vol->used_ebs - 1 &&
-           offset + len > vol->last_eb_bytes)
-               return -EINVAL;
+       if (vol->vol_type == UBI_STATIC_VOLUME) {
+               if (vol->used_ebs == 0)
+                       /* Empty static UBI volume */
+                       return 0;
+               if (lnum == vol->used_ebs - 1 &&
+                   offset + len > vol->last_eb_bytes)
+                       return -EINVAL;
+       }
 
        if (vol->upd_marker)
                return -EBADF;