提交 3df77072 编写于 作者: C Colin Ian King 提交者: Artem Bityutskiy

UBI: block: fix dereference on uninitialized dev

commit 4df38926 ("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: NColin Ian King <colin.king@canonical.com>
Acked-by: NEzequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: NArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
上级 1bf1890e
......@@ -504,11 +504,6 @@ static int ubiblock_resize(struct ubi_volume_info *vi)
struct ubiblock *dev;
u64 disk_capacity = ((u64)vi->size * vi->usable_leb_size) >> 9;
if ((sector_t)disk_capacity != disk_capacity) {
ubi_warn("%s: the volume is too big, cannot resize (%d LEBs)",
dev->gd->disk_name, vi->size);
return -EFBIG;
}
/*
* Need to lock the device list until we stop using the device,
* otherwise the device struct might get released in
......@@ -520,6 +515,12 @@ static int ubiblock_resize(struct ubi_volume_info *vi)
mutex_unlock(&devices_mutex);
return -ENODEV;
}
if ((sector_t)disk_capacity != disk_capacity) {
mutex_unlock(&devices_mutex);
ubi_warn("%s: the volume is too big (%d LEBs), cannot resize",
dev->gd->disk_name, vi->size);
return -EFBIG;
}
mutex_lock(&dev->dev_mutex);
set_capacity(dev->gd, disk_capacity);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册