summaryrefslogtreecommitdiff
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2017-12-15 15:39:51 +0300
committerBoris Brezillon <boris.brezillon@free-electrons.com>2018-01-06 17:09:40 +0300
commit33f45c44d68b3593826524ba6d02bd9cce9e101e (patch)
tree4a7246975527f107e7b09525ee85cca2cf76f940 /drivers/mtd/mtdcore.c
parent911c3a30cab8269239d24e68df4adf9f7f9e2a01 (diff)
downloadlinux-33f45c44d68b3593826524ba6d02bd9cce9e101e.tar.xz
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 <boris.brezillon@free-electrons.com> Reviewed-by: Miquel Raynal <miquel.raynal@free-electrons.com>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c5
1 files changed, 5 insertions, 0 deletions
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);