Skip to content

Commit 33f45c4

Browse files
author
Boris Brezillon
committed
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>
1 parent 911c3a3 commit 33f45c4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/mtd/mtdcore.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ int add_mtd_device(struct mtd_info *mtd)
503503
return -EEXIST;
504504

505505
BUG_ON(mtd->writesize == 0);
506+
507+
if (WARN_ON((!mtd->erasesize || !mtd->_erase) &&
508+
!(mtd->flags & MTD_NO_ERASE)))
509+
return -EINVAL;
510+
506511
mutex_lock(&mtd_table_mutex);
507512

508513
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);

0 commit comments

Comments
 (0)