diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2018-08-29 14:19:46 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-08-31 08:23:30 +0200 |
commit | 9f51b1b1d31f2cf1fc9afda504a372dfd5dfa067 (patch) | |
tree | a08a3d8289fcfca861b87bf0d9a2271b81d8dba3 /drivers/mtd/ubi | |
parent | fa92a9a3139a9dbea29bfb53608f6095a68bb0f7 (diff) | |
download | barebox-9f51b1b1d31f2cf1fc9afda504a372dfd5dfa067.tar.gz barebox-9f51b1b1d31f2cf1fc9afda504a372dfd5dfa067.tar.xz |
UBI: add an helper to check lnum validity
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>
[Fixed conflicts due missing cdev]
Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/kapi.c | 12 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 5 |
2 files changed, 11 insertions, 6 deletions
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 9ec9962a59..a7be941908 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c @@ -413,7 +413,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; @@ -458,7 +458,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; @@ -495,7 +495,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) @@ -555,7 +555,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) @@ -591,7 +591,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) @@ -626,7 +626,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) diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index d8e895ae47..4ef692fc72 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -778,6 +778,11 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id); void ubi_update_reserved(struct ubi_device *ubi); void ubi_calculate_reserved(struct ubi_device *ubi); +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); |