Hello Simon,
On 09.10.26 09:02, Simon Glass wrote:
Hi Heiko,
On 2026-10-04T04:06:44, Heiko Schocher <[email protected]> wrote:
mtd: align a partition on the write size if the device cannot erase
allocate_partition() aligns a partition on the erase size of its master
and checks the offset and the size against it with mtd_mod_by_eb(). A
device which cannot erase has no erase size, so that check divides by
zero, "mtd list" shows
### ERROR ### Please RESET the board ###
Linux aligns the partition of such a device on the write size instead,
see wr_alignment in allocate_partition() in drivers/mtd/mtdpart.c. Do
the same here, and take the alignment for the MTDPART_OFS_NXTBLK
rounding from the same place, which divided by the erase size as well.
Signed-off-by: Heiko Schocher <[email protected]>
drivers/mtd/mtdpart.c | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
@@ -563,8 +563,12 @@ static struct mtd_info *allocate_partition(struct mtd_info
*master,
+ u32 wr_alignment = (master->flags & MTD_NO_ERASE) ? master->writesize :
+ master->erasesize;
Patch 1 decides that a device cannot erase with !mtd->erasesize ||
!mtd->_erase, but this patch checks MTD_NO_ERASE, and the two don't
always agree. A driver that leaves erasesize at 0 without setting
MTD_NO_ERASE still divides by zero here, as does an MTD_NO_ERASE
driver that leaves writesize at 0. Since the point is to stop 'mtd
list' crashing, I suggest skipping the alignment checks, or adding a
WARN_ON(), when wr_alignment is 0, rather than relying on every driver
setting the flags correctly. What do you think?
Makes sense, I think I remove the alignment checks and add a WARN_ON()
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
@@ -731,19 +737,30 @@ static struct mtd_info *allocate_partition(struct
mtd_info *master,
+ tmp = slave->offset;
+ remainder = do_div(tmp, wr_alignment);
+ if ((slave->flags & MTD_WRITEABLE) && remainder) {
/* Doesn't start on a boundary of major erase size */
This comment is now out of date.
Will fix this in v3.
In any case:
Reviewed-by: Simon Glass <[email protected]>
Thanks!
bye,
HEiko
Regards,
Simon
--
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic