Skip to content

Commit

Permalink
mtd: Do not allow MTD devices with inconsistent erase properties
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Boris Brezillon committed Jan 6, 2018
1 parent 911c3a3 commit 33f45c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 33f45c4

Please sign in to comment.