All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Ashok Reddy Soma <ashok.reddy.soma@amd.com>,
	Abbarapu Venkatesh Yadav <venkyada@qti.qualcomm.com>,
	u-boot@lists.u-boot-project.org,
	Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] mtd: spi-nor: Return the error when write_bar() fails to wait for ready
Date: Thu,  3 Dec 2026 20:17:06 +0000	[thread overview]
Message-ID: <20261203201714.2129394-2-oss.patchbox@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-03 21:39 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=20261203201714.2129394-2-oss.patchbox@gmail.com \
    --to=oss.patchbox@gmail.com \
    --cc=ashok.reddy.soma@amd.com \
    --cc=takahiro.kuwano@infineon.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=venkyada@qti.qualcomm.com \
    --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.