From: Yuho Choi <oss.patchbox@gmail.com>
To: Vignesh R <vigneshr@ti.com>
Cc: Takahiro Kuwano <takahiro.kuwano@infineon.com>,
Tom Rini <trini@konsulko.com>,
u-boot@lists.u-boot-project.org,
Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] mtd: spi-nor: Don't let clean_bar() overwrite read/write errors
Date: Sun, 1 Nov 2026 22:29:45 -0500 [thread overview]
Message-ID: <20261102032950.305343-1-oss.patchbox@gmail.com> (raw)
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
reply other threads:[~2026-11-02 5:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102032950.305343-1-oss.patchbox@gmail.com \
--to=oss.patchbox@gmail.com \
--cc=takahiro.kuwano@infineon.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.