Linux SPI subsystem development
 help / color / mirror / Atom feed
From: David Carlier <devnexen@gmail.com>
To: Jyan Chou <jyanchou@realtek.com>, Yu-Chun Lin <eleanor.lin@realtek.com>
Cc: Mark Brown <broonie@kernel.org>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	David Carlier <devnexen@gmail.com>,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH] spi: rtk-nor: Limit exec_op writes to one byte per operation
Date: Fri, 30 Oct 2026 14:59:06 +0000	[thread overview]
Message-ID: <20261030145909.285144-1-devnexen@gmail.com> (raw)

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


                 reply	other threads:[~2026-10-30 14:59 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=20261030145909.285144-1-devnexen@gmail.com \
    --to=devnexen@gmail.com \
    --cc=broonie@kernel.org \
    --cc=eleanor.lin@realtek.com \
    --cc=jyanchou@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    /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