mtd: Fix partition alignment check on multi-erasesize devices

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Sep 28 02:59:01 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=7e439681af82984045efc215437ebb2ca8d33a4c
Commit:     7e439681af82984045efc215437ebb2ca8d33a4c
Parent:     73600b619bf8b9803a0610624a0e11f5ed8f761e
Author:     Boris Brezillon <boris.brezillon at free-electrons.com>
AuthorDate: Mon Sep 25 10:19:57 2017 +0200
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Wed Sep 27 13:53:20 2017 +0200

    mtd: Fix partition alignment check on multi-erasesize devices
    
    Commit 1eeef2d7483a ("mtd: handle partitioning on devices with 0
    erasesize") introduced a regression on heterogeneous erase region
    devices. Alignment of the partition was tested against the master
    eraseblock size which can be bigger than the slave one, thus leading
    to some partitions being marked as read-only.
    
    Update wr_alignment to match this slave erasesize after this erasesize
    has been determined by picking the biggest erasesize of all the regions
    embedded in the MTD partition.
    
    Reported-by: Mathias Thore <Mathias.Thore at infinera.com>
    Fixes: 1eeef2d7483a ("mtd: handle partitioning on devices with 0 erasesize")
    Cc: <stable at vger.kernel.org>
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
    Tested-by: Mathias Thore <Mathias.Thore at infinera.com>
    Reviewed-by: Mathias Thore <Mathias.Thore at infinera.com>
---
 drivers/mtd/mtdpart.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 5736b0c..a308e70 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -581,6 +581,14 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent,
 		slave->mtd.erasesize = parent->erasesize;
 	}
 
+	/*
+	 * Slave erasesize might differ from the master one if the master
+	 * exposes several regions with different erasesize. Adjust
+	 * wr_alignment accordingly.
+	 */
+	if (!(slave->mtd.flags & MTD_NO_ERASE))
+		wr_alignment = slave->mtd.erasesize;
+
 	tmp = slave->offset;
 	remainder = do_div(tmp, wr_alignment);
 	if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {



More information about the linux-mtd-cvs mailing list