diff options
author | Colin Ian King <colin.king@canonical.com> | 2014-08-20 05:19:38 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2014-09-16 12:02:04 -0400 |
commit | 3df770725339c41d1cd9be4da4ca0d968119d8ad (patch) | |
tree | 75ea40d96de8dce7450bbd306c22f6350c1e5edf /drivers/mtd/ubi | |
parent | 1bf1890e86869032099b539bc83b098be12fc5a7 (diff) |
UBI: block: fix dereference on uninitialized dev
commit 4df38926f337 ("UBI: block: Avoid disk size integer overflow")
introduced a dereference on dev (which is not initialized at that
point) when printing a warning message. Re-order disk_capacity check
after the dev is found.
Found by cppcheck:
[drivers/mtd/ubi/block.c:509]: (error) Uninitialized variable: dev
Artem: tweak the error message a bit
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/block.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 33c64955d4d7..518792b7634d 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c | |||
@@ -504,11 +504,6 @@ static int ubiblock_resize(struct ubi_volume_info *vi) | |||
504 | struct ubiblock *dev; | 504 | struct ubiblock *dev; |
505 | u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9; | 505 | u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9; |
506 | 506 | ||
507 | if ((sector_t)disk_capacity != disk_capacity) { | ||
508 | ubi_warn("%s: the volume is too big, cannot resize (%d LEBs)", | ||
509 | dev->gd->disk_name, vi->size); | ||
510 | return -EFBIG; | ||
511 | } | ||
512 | /* | 507 | /* |
513 | * Need to lock the device list until we stop using the device, | 508 | * Need to lock the device list until we stop using the device, |
514 | * otherwise the device struct might get released in | 509 | * otherwise the device struct might get released in |
@@ -520,6 +515,12 @@ static int ubiblock_resize(struct ubi_volume_info *vi) | |||
520 | mutex_unlock(&devices_mutex); | 515 | mutex_unlock(&devices_mutex); |
521 | return -ENODEV; | 516 | return -ENODEV; |
522 | } | 517 | } |
518 | if ((sector_t)disk_capacity != disk_capacity) { | ||
519 | mutex_unlock(&devices_mutex); | ||
520 | ubi_warn("%s: the volume is too big (%d LEBs), cannot resize", | ||
521 | dev->gd->disk_name, vi->size); | ||
522 | return -EFBIG; | ||
523 | } | ||
523 | 524 | ||
524 | mutex_lock(&dev->dev_mutex); | 525 | mutex_lock(&dev->dev_mutex); |
525 | set_capacity(dev->gd, disk_capacity); | 526 | set_capacity(dev->gd, disk_capacity); |