From: Vikrant Yadav <vikrantyadav4802@gmail.com>
To: lorenzo@kernel.org, ray.liu@airoha.com
Cc: broonie@kernel.org, mikhail.kshevet@gmail.com,
linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org,
Vikrant Yadav <vikrantyadav4802@gmail.com>
Subject: [PATCH] spi: airoha-snfi: strip plane select bit from dirmap offs
Date: Mon, 30 Nov 2026 21:57:43 +0530 [thread overview]
Message-ID: <20261130162743.12168-1-vikrantyadav4802@gmail.com> (raw)
When a SPI NAND chip sets SPINAND_HAS_READ_PLANE_SELECT_BIT or
SPINAND_HAS_PROG_PLANE_SELECT_BIT (e.g. Macronix MX35LF2GE4AB), the
SPI NAND core ORs the plane into the column address it passes to the
dirmap callbacks as offs:
offs = (plane << fls(page_size)) | column
For a 2048-byte page, plane 1 sets bit 12, so offs is 0x1000 for a
data or data+OOB access and 0x1800 for an OOB-only read.
airoha_snand_dirmap_read() and airoha_snand_dirmap_write() use offs as
a plain byte offset into txrx_buf (SPI_NAND_CACHE_SIZE, 4352 bytes) and
to size the transfer. With the plane bit left in, on plane 1:
- bytes = round_up(offs + len, 64) is inflated (6208 instead of 2112
for an OOB-only read), so the NFI is programmed with an oversized
transfer length.
- read: memcpy(buf, txrx_buf + offs, len) copies from past the end of
txrx_buf.
- write: memset()/memcpy() on txrx_buf + offs write past the end of
txrx_buf, corrupting memory.
The plane is already selected through desc->info.offset (set at dirmap
creation as plane << fls(page_size)), which the driver writes to the
hardware address registers (REG_SPI_NFI_RD_CTL3 for read,
REG_SPI_NFI_PG_CTL2 for write). Only the use of offs as a buffer index
and length is wrong.
Clear the plane bit from offs at the start of both functions:
offs &= ~desc->info.offset;
info.offset contains only the plane bit, so the column is unchanged.
This is a no-op for plane 0 and for chips without the plane select
flags, and works whether the chip sets the read flag, the program flag
or both.
Fixes: 902c0ea18a97 ("spi: airoha: avoid reading flash page settings from SNFI registers during driver startup")
Signed-off-by: Vikrant Yadav <vikrantyadav4802@gmail.com>
---
drivers/spi/spi-airoha-snfi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index 95bfde7c8e7f..2217df3c3677 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -565,6 +565,9 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc,
as_ctrl = spi_controller_get_devdata(spi->controller);
+ /* offs may carry the plane select bit, keep only the column */
+ offs &= ~desc->info.offset;
+
/* minimum oob size is 64 */
bytes = round_up(offs + len, 64);
@@ -758,6 +761,9 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
as_ctrl = spi_controller_get_devdata(spi->controller);
+ /* offs may carry the plane select bit, keep only the column */
+ offs &= ~desc->info.offset;
+
/* minimum oob size is 64 */
bytes = round_up(offs + len, 64);
--
2.34.1
reply other threads:[~2026-11-30 16:28 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=20261130162743.12168-1-vikrantyadav4802@gmail.com \
--to=vikrantyadav4802@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=mikhail.kshevet@gmail.com \
--cc=ray.liu@airoha.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox