Skip to content

Commit ad46351

Browse files
committed
mtd: Make sure mtd->erasesize is valid even if the partition is of size 0
Commit 33f45c4 ("mtd: Do not allow MTD devices with inconsistent erase properties") introduced a check to make sure ->erasesize and ->_erase values are consistent with the MTD_NO_ERASE flag. This patch did not take the 0 bytes partition case into account which can happen when the defined partition is outside the flash device memory range. Fix that by setting the partition erasesize to the parent erasesize. Fixes: 33f45c4 ("mtd: Do not allow MTD devices with inconsistent erase properties") Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Cc: <stable@vger.kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Boris Brezillon <bbrezillon@kernel.org> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent bda2ab5 commit ad46351

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/mtd/mtdpart.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent,
480480
/* let's register it anyway to preserve ordering */
481481
slave->offset = 0;
482482
slave->mtd.size = 0;
483+
484+
/* Initialize ->erasesize to make add_mtd_device() happy. */
485+
slave->mtd.erasesize = parent->erasesize;
486+
483487
printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
484488
part->name);
485489
goto out_register;

0 commit comments

Comments
 (0)