]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
UBI: add an helper to check lnum validity
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Fri, 16 Sep 2016 14:59:22 +0000 (16:59 +0200)
committerRichard Weinberger <richard@nod.at>
Sun, 2 Oct 2016 20:48:14 +0000 (22:48 +0200)
ubi_leb_valid() is here to replace the
lnum < 0 || lnum >= vol->reserved_pebs checks.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/cdev.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/ubi.h

index 3490dcd99ad1fa575eba545bb87617b73d46de8b..45c329694a5e1479b8387da1eba1f57e5302f4d8 100644 (file)
@@ -454,7 +454,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
 
                /* Validate the request */
                err = -EINVAL;
-               if (req.lnum < 0 || req.lnum >= vol->reserved_pebs ||
+               if (!ubi_leb_valid(vol, req.lnum) ||
                    req.bytes < 0 || req.bytes > vol->usable_leb_size)
                        break;
 
@@ -485,7 +485,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
                        break;
                }
 
-               if (lnum < 0 || lnum >= vol->reserved_pebs) {
+               if (!ubi_leb_valid(vol, lnum)) {
                        err = -EINVAL;
                        break;
                }
index a9e2cef7c95c24c0deb4d6500d7da7f00424db7b..cec7f65beb9e69b7cd77da9bf053b5d509080c12 100644 (file)
@@ -538,7 +538,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
        if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
                return -EROFS;
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 ||
+       if (!ubi_leb_valid(vol, lnum) || offset < 0 || len < 0 ||
            offset + len > vol->usable_leb_size ||
            offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1))
                return -EINVAL;
@@ -583,7 +583,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
        if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
                return -EROFS;
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 ||
+       if (!ubi_leb_valid(vol, lnum) || len < 0 ||
            len > vol->usable_leb_size || len & (ubi->min_io_size - 1))
                return -EINVAL;
 
@@ -620,7 +620,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
        if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
                return -EROFS;
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs)
+       if (!ubi_leb_valid(vol, lnum))
                return -EINVAL;
 
        if (vol->upd_marker)
@@ -680,7 +680,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum)
        if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
                return -EROFS;
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs)
+       if (!ubi_leb_valid(vol, lnum))
                return -EINVAL;
 
        if (vol->upd_marker)
@@ -716,7 +716,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum)
        if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
                return -EROFS;
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs)
+       if (!ubi_leb_valid(vol, lnum))
                return -EINVAL;
 
        if (vol->upd_marker)
@@ -751,7 +751,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum)
 
        dbg_gen("test LEB %d:%d", vol->vol_id, lnum);
 
-       if (lnum < 0 || lnum >= vol->reserved_pebs)
+       if (!ubi_leb_valid(vol, lnum))
                return -EINVAL;
 
        if (vol->upd_marker)
index b51d398f235665f23e82aa29892b4b440f371d7d..23c902e204aa265016ba426404480244a2d17cd5 100644 (file)
@@ -843,6 +843,11 @@ void ubi_update_reserved(struct ubi_device *ubi);
 void ubi_calculate_reserved(struct ubi_device *ubi);
 int ubi_check_pattern(const void *buf, uint8_t patt, int size);
 
+static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum)
+{
+       return lnum >= 0 && lnum < vol->reserved_pebs;
+}
+
 /* eba.c */
 int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
                      int lnum);