mtd: spi-nor: Don't let clean_bar() overwrite read/write errors
PATCH 1/1 mtd: spi-nor: Don't let clean_bar() overwrite read/write errors
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").
---
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(-)
drivers/mtd/spi/spi-nor-core.c +8 -2
@@ -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; }
Signature · 1 line
2.43.0
Quoted 14 lines
With
SPI_FLASH_BARenabled,spi_nor_read()andspi_nor_write()callclean_bar()at their common exit label and assign its return value to ret. This is also done on the error paths, so an error fromnor->read(),nor->write()orspi_nor_wait_till_ready()is replaced by the result ofclean_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 forspi_nor_erase()in commita9d9d412e00e("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 <[email protected]>
Quoted 8 lines
---
Tested on sandbox with SPI_FLASH_BAR=y and the emulated m25p16, using gdb to makespi_nor_read_data()andspi_nor_write_data()return-EIOafter the probe. Without this patch 'sf read' and 'sf write' print OK; with it they print ERROR -5. 'ut dmspi_flash' and
'ut dmspi_flash_func' pass, and a normal erase/write/read/compare still works. Not tested on hardware.
Quoted 9 lines · Yuho Choi
With
SPI_FLASH_BARenabled,spi_nor_read()andspi_nor_write()callclean_bar()at their common exit label and assign its return value to ret. This is also done on the error paths, so an error fromnor->read(),nor->write()orspi_nor_wait_till_ready()is replaced by the result ofclean_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.[...]
Applied to u-boot/main, thanks!
[1/1] mtd: spi-nor: Don't let clean_bar() overwrite read/write errors
commit: a38a1d2736eed7978df10f513a5f6df4075b2277
Signature · 1 line
Tom