* [PATCH] mtd: rawnand: samsung: fix pages_per_eraseblock calculation
@ 2026-10-23 8:16 Shuai Liu
0 siblings, 0 replies; only message in thread
From: Shuai Liu @ 2026-10-23 8:16 UTC (permalink / raw)
To: linux-mtd; +Cc: miquel.raynal, richard, vigneshr, linux-kernel, kevinshq
In samsung_nand_decode_id(), the division by memorg->pagesize binds
tighter than the left shift due to C operator precedence, so the
expression is evaluated as:
(128 * 1024) << (shift / pagesize)
The shift amount is at most 7 while pagesize is at least 2048, so the
integer division always yields 0 and pages_per_eraseblock ends up
being 131072 regardless of the actual chip geometry.
nanddev_init() later computes mtd->erasesize as
pagesize * pages_per_eraseblock, overwriting the correct value set in
this function with an astronomic value (e.g. 0x20000000, 512 MiB, for
a chip with 4096-byte pages). MTD then rejects partitions not
starting on such an eraseblock boundary and forces them read-only,
breaking the rootfs on affected boards.
Add parentheses around the shift expression so that the eraseblock
size is computed before being divided by the page size.
Reported-by: kevinshq <kevinshq@163.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222140
Fixes: 629a442cad5f ("mtd: rawnand: Fill memorg during detection")
Signed-off-by: Shuai Liu <847807867@qq.com>
---
drivers/mtd/nand/raw/nand_samsung.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/raw/nand_samsung.c b/drivers/mtd/nand/raw/nand_samsung.c
index 0be6b7563..765c0a7d8 100644
--- a/drivers/mtd/nand/raw/nand_samsung.c
+++ b/drivers/mtd/nand/raw/nand_samsung.c
@@ -63,9 +63,9 @@ static void samsung_nand_decode_id(struct nand_chip *chip)
/* Get blocksize */
extid >>= 2;
- memorg->pages_per_eraseblock = (128 * 1024) <<
- (((extid >> 1) & 0x04) |
- (extid & 0x03)) /
+ memorg->pages_per_eraseblock = ((128 * 1024) <<
+ (((extid >> 1) & 0x04) |
+ (extid & 0x03))) /
memorg->pagesize;
mtd->erasesize = (128 * 1024) <<
(((extid >> 1) & 0x04) | (extid & 0x03));
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 8:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 8:16 [PATCH] mtd: rawnand: samsung: fix pages_per_eraseblock calculation Shuai Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®