* [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
@ 2026-05-27 17:37 Santhosh Kumar K
2026-05-28 9:27 ` Miquel Raynal
2026-05-28 12:50 ` Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Santhosh Kumar K @ 2026-05-27 17:37 UTC (permalink / raw)
To: broonie, miquel.raynal, xtydtc, vigneshr
Cc: linux-spi, linux-kernel, s-k6, stable
spi_mem_supports_op() accepts a const struct spi_mem_op pointer but
casts away const internally to call spi_mem_adjust_op_freq(). This
mutates the caller's op template, which causes stale max_freq values
when callers reuse persistent templates - subsequent calls won't
re-apply the device frequency cap since spi_mem_adjust_op_freq()
skips non-zero values.
Fix by operating on a stack-local copy instead.
Fixes: a4f8e70d75dd ("spi: spi-mem: add spi_mem_adjust_op_freq() in spi_mem_supports_op()")
Cc: Tianyu Xu <xtydtc@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
This patch was tested on TI's
AM62Ax SK with OSPI NAND flash and
AM62Px SK with OSPI NOR flash.
log: https://gist.github.com/santhosh21/1747d197b12635bfaed741fca650a173
---
drivers/spi/spi-mem.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index f64eda9bbd9f..a88b9f038356 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -279,13 +279,20 @@ static bool spi_mem_internal_supports_op(struct spi_mem *mem,
*/
bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
{
- /* Make sure the operation frequency is correct before going futher */
- spi_mem_adjust_op_freq(mem, (struct spi_mem_op *)op);
+ struct spi_mem_op eval_op = *op;
+
+ /*
+ * Work on a local copy; this is a pure capability check and must
+ * not modify the caller's op. Stored templates with max_freq == 0
+ * must remain unset so their frequency is always re-capped to the
+ * current device maximum at execution time.
+ */
+ spi_mem_adjust_op_freq(mem, &eval_op);
- if (spi_mem_check_op(op))
+ if (spi_mem_check_op(&eval_op))
return false;
- return spi_mem_internal_supports_op(mem, op);
+ return spi_mem_internal_supports_op(mem, &eval_op);
}
EXPORT_SYMBOL_GPL(spi_mem_supports_op);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
2026-05-27 17:37 [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op() Santhosh Kumar K
@ 2026-05-28 9:27 ` Miquel Raynal
2026-05-28 12:50 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2026-05-28 9:27 UTC (permalink / raw)
To: Santhosh Kumar K
Cc: broonie, xtydtc, vigneshr, linux-spi, linux-kernel, stable
> spi_mem_supports_op() accepts a const struct spi_mem_op pointer but
> casts away const internally to call spi_mem_adjust_op_freq(). This
> mutates the caller's op template, which causes stale max_freq values
> when callers reuse persistent templates - subsequent calls won't
> re-apply the device frequency cap since spi_mem_adjust_op_freq()
> skips non-zero values.
>
> Fix by operating on a stack-local copy instead.
>
> Fixes: a4f8e70d75dd ("spi: spi-mem: add spi_mem_adjust_op_freq() in spi_mem_supports_op()")
> Cc: Tianyu Xu <xtydtc@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
> ---
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
2026-05-27 17:37 [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op() Santhosh Kumar K
2026-05-28 9:27 ` Miquel Raynal
@ 2026-05-28 12:50 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-05-28 12:50 UTC (permalink / raw)
To: miquel.raynal, xtydtc, vigneshr, Santhosh Kumar K
Cc: linux-spi, linux-kernel, stable
On Wed, 27 May 2026 23:07:36 +0530, Santhosh Kumar K wrote:
> spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.1
Thanks!
[1/1] spi: spi-mem: avoid mutating op template in spi_mem_supports_op()
https://git.kernel.org/broonie/spi/c/79378db6a86c
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-29 14:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 17:37 [PATCH] spi: spi-mem: avoid mutating op template in spi_mem_supports_op() Santhosh Kumar K
2026-05-28 9:27 ` Miquel Raynal
2026-05-28 12:50 ` Mark Brown
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.