diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-09-16 10:59:22 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2016-10-02 16:48:14 -0400 |
commit | 9a5f09ac0ab83e4a965a24edd6cf7cb0303c6dc9 (patch) | |
tree | 585c31efc8dc614a7bc705f73cfb8c69ae728913 /drivers/mtd/ubi | |
parent | 2d78aee426d821bbecbc80ee96ada5730ee68b6f (diff) |
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>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/cdev.c | 4 | ||||
-rw-r--r-- | drivers/mtd/ubi/kapi.c | 12 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 5 |
3 files changed, 13 insertions, 8 deletions
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 3490dcd99ad1..45c329694a5e 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -454,7 +454,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd, | |||
454 | 454 | ||
455 | /* Validate the request */ | 455 | /* Validate the request */ |
456 | err = -EINVAL; | 456 | err = -EINVAL; |
457 | if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || | 457 | if (!ubi_leb_valid(vol, req.lnum) || |
458 | req.bytes < 0 || req.bytes > vol->usable_leb_size) | 458 | req.bytes < 0 || req.bytes > vol->usable_leb_size) |
459 | break; | 459 | break; |
460 | 460 | ||
@@ -485,7 +485,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd, | |||
485 | break; | 485 | break; |
486 | } | 486 | } |
487 | 487 | ||
488 | if (lnum < 0 || lnum >= vol->reserved_pebs) { | 488 | if (!ubi_leb_valid(vol, lnum)) { |
489 | err = -EINVAL; | 489 | err = -EINVAL; |
490 | break; | 490 | break; |
491 | } | 491 | } |
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index a9e2cef7c95c..cec7f65beb9e 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c | |||
@@ -538,7 +538,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, | |||
538 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | 538 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) |
539 | return -EROFS; | 539 | return -EROFS; |
540 | 540 | ||
541 | if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 || | 541 | if (!ubi_leb_valid(vol, lnum) || offset < 0 || len < 0 || |
542 | offset + len > vol->usable_leb_size || | 542 | offset + len > vol->usable_leb_size || |
543 | offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) | 543 | offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) |
544 | return -EINVAL; | 544 | return -EINVAL; |
@@ -583,7 +583,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | |||
583 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | 583 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) |
584 | return -EROFS; | 584 | return -EROFS; |
585 | 585 | ||
586 | if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 || | 586 | if (!ubi_leb_valid(vol, lnum) || len < 0 || |
587 | len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) | 587 | len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) |
588 | return -EINVAL; | 588 | return -EINVAL; |
589 | 589 | ||
@@ -620,7 +620,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum) | |||
620 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | 620 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) |
621 | return -EROFS; | 621 | return -EROFS; |
622 | 622 | ||
623 | if (lnum < 0 || lnum >= vol->reserved_pebs) | 623 | if (!ubi_leb_valid(vol, lnum)) |
624 | return -EINVAL; | 624 | return -EINVAL; |
625 | 625 | ||
626 | if (vol->upd_marker) | 626 | if (vol->upd_marker) |
@@ -680,7 +680,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum) | |||
680 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | 680 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) |
681 | return -EROFS; | 681 | return -EROFS; |
682 | 682 | ||
683 | if (lnum < 0 || lnum >= vol->reserved_pebs) | 683 | if (!ubi_leb_valid(vol, lnum)) |
684 | return -EINVAL; | 684 | return -EINVAL; |
685 | 685 | ||
686 | if (vol->upd_marker) | 686 | if (vol->upd_marker) |
@@ -716,7 +716,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum) | |||
716 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | 716 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) |
717 | return -EROFS; | 717 | return -EROFS; |
718 | 718 | ||
719 | if (lnum < 0 || lnum >= vol->reserved_pebs) | 719 | if (!ubi_leb_valid(vol, lnum)) |
720 | return -EINVAL; | 720 | return -EINVAL; |
721 | 721 | ||
722 | if (vol->upd_marker) | 722 | if (vol->upd_marker) |
@@ -751,7 +751,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum) | |||
751 | 751 | ||
752 | dbg_gen("test LEB %d:%d", vol->vol_id, lnum); | 752 | dbg_gen("test LEB %d:%d", vol->vol_id, lnum); |
753 | 753 | ||
754 | if (lnum < 0 || lnum >= vol->reserved_pebs) | 754 | if (!ubi_leb_valid(vol, lnum)) |
755 | return -EINVAL; | 755 | return -EINVAL; |
756 | 756 | ||
757 | if (vol->upd_marker) | 757 | if (vol->upd_marker) |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index b51d398f2356..23c902e204aa 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -843,6 +843,11 @@ void ubi_update_reserved(struct ubi_device *ubi); | |||
843 | void ubi_calculate_reserved(struct ubi_device *ubi); | 843 | void ubi_calculate_reserved(struct ubi_device *ubi); |
844 | int ubi_check_pattern(const void *buf, uint8_t patt, int size); | 844 | int ubi_check_pattern(const void *buf, uint8_t patt, int size); |
845 | 845 | ||
846 | static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum) | ||
847 | { | ||
848 | return lnum >= 0 && lnum < vol->reserved_pebs; | ||
849 | } | ||
850 | |||
846 | /* eba.c */ | 851 | /* eba.c */ |
847 | int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, | 852 | int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, |
848 | int lnum); | 853 | int lnum); |