From: Boris Brezillon Date: Fri, 15 Dec 2017 12:39:51 +0000 (+0100) Subject: mtd: Do not allow MTD devices with inconsistent erase properties X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=33f45c44d68b3593826524ba6d02bd9cce9e101e;p=openwrt%2Fstaging%2Fblogic.git mtd: Do not allow MTD devices with inconsistent erase properties When mtd->erasesize is 0 or mtd->_erase is NULL, that means the device does not support the erase operation, which in turn means it should have the MTD_NO_ERASE flag set. Signed-off-by: Boris Brezillon Reviewed-by: Miquel Raynal --- diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index f80e911b8843..642c35dde686 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -503,6 +503,11 @@ int add_mtd_device(struct mtd_info *mtd) return -EEXIST; BUG_ON(mtd->writesize == 0); + + if (WARN_ON((!mtd->erasesize || !mtd->_erase) && + !(mtd->flags & MTD_NO_ERASE))) + return -EINVAL; + mutex_lock(&mtd_table_mutex); i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);