Skip to content

Commit 017c73a

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
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: 801c135 ("UBI: Unsorted Block Images") Reported-by: Yu Hao <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/T/ Signed-off-by: Zhihao Cheng <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 4a0fc73 commit 017c73a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/mtd/ubi/build.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
894894
return -EINVAL;
895895
}
896896

897+
/* UBI cannot work on flashes with zero erasesize. */
898+
if (!mtd->erasesize) {
899+
pr_err("ubi: refuse attaching mtd%d - zero erasesize flash is not supported\n",
900+
mtd->index);
901+
return -EINVAL;
902+
}
903+
897904
if (ubi_num == UBI_DEV_NUM_AUTO) {
898905
/* Search for an empty slot in the @ubi_devices array */
899906
for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)

0 commit comments

Comments
 (0)