All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: Return the error when write_bar() fails to wait for ready
@ 2026-12-03 20:17 Yuho Choi
  0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-12-03 20:17 UTC (permalink / raw)
  To: Vignesh R
  Cc: Takahiro Kuwano, Tom Rini, Ashok Reddy Soma,
	Abbarapu Venkatesh Yadav, u-boot, Yuho Choi

write_bar() returns 1 when waiting for the flash to become ready fails,
but its callers only treat negative values as errors. The read, write
or erase then goes on without switching the bank and uses the same
offset in the previously selected 16 MiB bank: a read returns data from
the wrong bank as a success, and a write or erase changes the wrong bank.

Return the error from spi_nor_wait_till_ready() instead.

Fixes: c480ec2c45b2 ("mtd: spi-nor: Add parallel and stacked memories support in read_bar and write_bar")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
An LLM helped write this patch and the reproduction test, and run the test.

Tested on sandbox (origin/main d1caced3a43) with SPI_FLASH_BAR=y. The
sandbox SPI flash emulator was changed locally, not in this patch, to
emulate a 32 MiB w25q256 with an extended address register and to fail
one status register read on request, so the wait at the start of
write_bar() fails. Bank 0 was filled with 0xaa and bank 1 with 0x55.

Before:
  sf read 0x10000 0x1000000 0x100  -> "Read: OK", but the data is 0xaa
  sf erase 0x1000000 0x1000        -> "Erased: OK", but offset 0x0
                                      reads back 0xff afterwards and
                                      0x1000000 still reads 0x55
After:
  both commands fail with -EIO and the flash is unchanged.

ut dm spi_flash and ut dm spi_flash_func pass before and after.

 drivers/mtd/spi/spi-nor-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 7bc889c9629..57640908765 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -966,8 +966,9 @@ static int write_bar(struct spi_nor *nor, u32 offset)
 	struct mtd_info *mtd = &nor->mtd;
 
 	/* Wait until previous write command is finished */
-	if (spi_nor_wait_till_ready(nor))
-		return 1;
+	ret = spi_nor_wait_till_ready(nor);
+	if (ret)
+		return ret;
 
 	if (nor->flags & (SNOR_F_HAS_PARALLEL | SNOR_F_HAS_STACKED) &&
 	    mtd->size <= SZ_32M)

base-commit: d1caced3a435607435cb7969e34499051a4ac1e6
-- 
2.56.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 21:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:17 [PATCH] mtd: spi-nor: Return the error when write_bar() fails to wait for ready Yuho Choi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.