* [PATCH] mtd: spi-nor: Don't let clean_bar() overwrite read/write errors
@ 2026-11-02 3:29 Yuho Choi
0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-11-02 3:29 UTC (permalink / raw)
To: Vignesh R; +Cc: Takahiro Kuwano, Tom Rini, u-boot, Yuho Choi
With SPI_FLASH_BAR enabled, spi_nor_read() and spi_nor_write() call
clean_bar() at their common exit label and assign its return value to
ret. This is also done on the error paths, so an error from
nor->read(), nor->write() or spi_nor_wait_till_ready() is replaced by
the result of clean_bar(), which is 0 when the bank register is already
0 or was reset successfully. The caller then gets 0 back for a read or
write that did not complete.
Only use the result of clean_bar() when no earlier error occurred, as
was done for spi_nor_erase() in commit a9d9d412e00e ("mtd: spi-nor-core:
Don't overwrite return value if it is non-zero").
Fixes: 8c927809ea96 ("mtd: spi: spi-nor-core: Add back U-Boot specific features")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Tested on sandbox with SPI_FLASH_BAR=y and the emulated m25p16, using
gdb to make spi_nor_read_data() and spi_nor_write_data() return -EIO
after the probe. Without this patch 'sf read' and 'sf write' print OK;
with it they print ERROR -5. 'ut dm spi_flash' and
'ut dm spi_flash_func' pass, and a normal erase/write/read/compare
still works. Not tested on hardware.
drivers/mtd/spi/spi-nor-core.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 937d79af64e..759f511fa20 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1677,7 +1677,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
read_err:
#if CONFIG_IS_ENABLED(SPI_FLASH_BAR)
- ret = clean_bar(nor);
+ if (ret)
+ clean_bar(nor);
+ else
+ ret = clean_bar(nor);
#endif
return ret;
}
@@ -2105,7 +2108,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
write_err:
#if CONFIG_IS_ENABLED(SPI_FLASH_BAR)
- ret = clean_bar(nor);
+ if (ret)
+ clean_bar(nor);
+ else
+ ret = clean_bar(nor);
#endif
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-02 5:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 3:29 [PATCH] mtd: spi-nor: Don't let clean_bar() overwrite read/write errors Yuho Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox