Skip to contentSkip to conversation

mtd: spi-nor: Don't let clean_bar() overwrite read/write errors

PATCH In review Yuho Choi 3 participants 3 messages Nov 2 – Nov 12 Memory technology devices (MTD)

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

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").

Fixes 8c927809ea96 ("mtd: spi: spi-nor-core: Add back U-Boot specific features")

---
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
index 937d79af64e..759f511fa20 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines

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")
Quoted 8 lines

---
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.

#2 lore raw
In reply to Yuho Choi
Quoted 9 lines · 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.

[...]

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