]> Git Repo - J-linux.git/commitdiff
ubi: Refuse attaching if mtd's erasesize is 0
authorZhihao Cheng <[email protected]>
Sun, 23 Apr 2023 11:10:41 +0000 (19:10 +0800)
committerRichard Weinberger <[email protected]>
Thu, 7 Sep 2023 19:59:04 +0000 (21:59 +0200)
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 <[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]>
drivers/mtd/ubi/build.c

index 8b91a55ec0d28827d57fbfb42d405402f738ab71..8ee51e49fced559d3a5e561956103cb53d6fcf50 100644 (file)
@@ -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++)
This page took 0.053225 seconds and 4 git commands to generate.