Commit 33f45c44 authored by Boris Brezillon's avatar Boris Brezillon

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: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: default avatarMiquel Raynal <miquel.raynal@free-electrons.com>
parent 911c3a30
...@@ -503,6 +503,11 @@ int add_mtd_device(struct mtd_info *mtd) ...@@ -503,6 +503,11 @@ int add_mtd_device(struct mtd_info *mtd)
return -EEXIST; return -EEXIST;
BUG_ON(mtd->writesize == 0); BUG_ON(mtd->writesize == 0);
if (WARN_ON((!mtd->erasesize || !mtd->_erase) &&
!(mtd->flags & MTD_NO_ERASE)))
return -EINVAL;
mutex_lock(&mtd_table_mutex); mutex_lock(&mtd_table_mutex);
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL); i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment