diff options
author | Zhihao Cheng <chengzhihao1@huawei.com> | 2023-04-23 14:10:41 +0300 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2023-09-07 22:59:04 +0300 |
commit | 017c73a34a661a861712f7cc1393a123e5b2208c (patch) | |
tree | 15aac188fc114504c4b2173d5b04f4d0bcedf955 /drivers/mtd/ubi/build.c | |
parent | 4a0fc73da97efd23a383ca839e6fe86410268f6b (diff) | |
download | linux-017c73a34a661a861712f7cc1393a123e5b2208c.tar.xz |
ubi: Refuse attaching if mtd's erasesize is 0
There exists mtd devices with zero erasesize, which will trigger a
divide-by-zero exception while attaching ubi device.
Fix it by refusing attaching if mtd's erasesize is 0.
Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
Reported-by: Yu Hao <yhao016@ucr.edu>
Link: https://lore.kernel.org/lkml/977347543.226888.1682011999468.JavaMail.zimbra@nod.at/T/
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'drivers/mtd/ubi/build.c')
-rw-r--r-- | drivers/mtd/ubi/build.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 8b91a55ec0d2..8ee51e49fced 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -894,6 +894,13 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, return -EINVAL; } + /* UBI cannot work on flashes with zero erasesize. */ + if (!mtd->erasesize) { + pr_err("ubi: refuse attaching mtd%d - zero erasesize flash is not supported\n", + mtd->index); + return -EINVAL; + } + if (ubi_num == UBI_DEV_NUM_AUTO) { /* Search for an empty slot in the @ubi_devices array */ for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) |