* [PATCH] spi: rtk-nor: Limit exec_op writes to one byte per operation
@ 2026-10-30 14:59 David Carlier
0 siblings, 0 replies; only message in thread
From: David Carlier @ 2026-10-30 14:59 UTC (permalink / raw)
To: Jyan Chou, Yu-Chun Lin
Cc: Mark Brown, linux-spi, linux-kernel, David Carlier, Sashiko
rtk_spi_do_write_and_cmds() issues a single writeb() to the data window,
so only the first byte of an addressed write reaches the flash, yet
exec_op reports success for the whole buffer. spi-nor hits this when
writing without a dirmap descriptor, e.g. for OTP security registers.
Such ops cannot be rejected in supports_op, since spi-nor probes page
program support with an addressed two byte write. Clamp them to one byte
in adjust_op_size instead, so spi-nor loops over the buffer.
Fixes: aca8cbecdd2e ("spi: spi-mem: Add Realtek SPI NOR flash controller driver")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260930071125.529791F000FF@smtp.kernel.org/
Signed-off-by: David Carlier <devnexen@gmail.com>
---
drivers/spi/spi-rtk-nor.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/spi/spi-rtk-nor.c b/drivers/spi/spi-rtk-nor.c
index 75856c31d2e6..55ea7c371854 100644
--- a/drivers/spi/spi-rtk-nor.c
+++ b/drivers/spi/spi-rtk-nor.c
@@ -357,6 +357,18 @@ static bool rtk_spi_supports_op(struct spi_mem *mem,
return spi_mem_default_supports_op(mem, op);
}
+static int rtk_spi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
+{
+ /*
+ * A write through exec_op is a single access to the data window,
+ * which programs one byte. Let the caller split longer writes.
+ */
+ if (op->data.dir == SPI_MEM_DATA_OUT && op->addr.nbytes)
+ op->data.nbytes = min(op->data.nbytes, 1U);
+
+ return 0;
+}
+
static int rtk_spi_dirmap_create(struct spi_mem_dirmap_desc *desc)
{
const struct spi_mem_op *op = desc->info.op_tmpl;
@@ -449,6 +461,7 @@ static const struct spi_controller_mem_ops rtk_spi_mem_ops = {
.dirmap_create = rtk_spi_dirmap_create,
.dirmap_read = rtk_spi_dirmap_read,
.dirmap_write = rtk_spi_dirmap_write,
+ .adjust_op_size = rtk_spi_adjust_op_size,
};
static int rtk_spi_probe(struct platform_device *pdev)
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-30 14:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 14:59 [PATCH] spi: rtk-nor: Limit exec_op writes to one byte per operation David Carlier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox