diff mbox series

mtd: parsers: bcm47xxpart: Fix halfblock reads

Message ID 20221013222855.2384881-1-linus.walleij@linaro.org
State Superseded
Headers show
Series mtd: parsers: bcm47xxpart: Fix halfblock reads | expand

Commit Message

Linus Walleij Oct. 13, 2022, 10:28 p.m. UTC
There is some code in the parser that tries to read 0x8000
bytes into a block to "read in the middle" of the block. Well
that only works if the block is also 0x10000 bytes all the time,
else we get these parse errors as we reach the end of the flash:

spi-nor spi0.0: mx25l1606e (2048 Kbytes)
mtd_read error while parsing (offset: 0x200000): -22
mtd_read error while parsing (offset: 0x201000): -22
(...)

Fix the code to do what I think was intended.

Cc: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/mtd/parsers/bcm47xxpart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Florian Fainelli Oct. 17, 2022, 10:18 p.m. UTC | #1
On 10/13/22 15:28, Linus Walleij wrote:
> There is some code in the parser that tries to read 0x8000
> bytes into a block to "read in the middle" of the block. Well
> that only works if the block is also 0x10000 bytes all the time,
> else we get these parse errors as we reach the end of the flash:
> 
> spi-nor spi0.0: mx25l1606e (2048 Kbytes)
> mtd_read error while parsing (offset: 0x200000): -22

Is it worth a Fixes: tag so it reaches stable eventually and we have 
this reach OpenWrt directly where it is presumably the most useful?
diff mbox series

Patch

diff --git a/drivers/mtd/parsers/bcm47xxpart.c b/drivers/mtd/parsers/bcm47xxpart.c
index 50fcf4c2174b..13daf9bffd08 100644
--- a/drivers/mtd/parsers/bcm47xxpart.c
+++ b/drivers/mtd/parsers/bcm47xxpart.c
@@ -233,11 +233,11 @@  static int bcm47xxpart_parse(struct mtd_info *master,
 		}
 
 		/* Read middle of the block */
-		err = mtd_read(master, offset + 0x8000, 0x4, &bytes_read,
+		err = mtd_read(master, offset + (blocksize / 2), 0x4, &bytes_read,
 			       (uint8_t *)buf);
 		if (err && !mtd_is_bitflip(err)) {
 			pr_err("mtd_read error while parsing (offset: 0x%X): %d\n",
-			       offset + 0x8000, err);
+			       offset + (blocksize / 2), err);
 			continue;
 		}