[PATCH RFC v2 04/35] spi: spi-mem: Sanitize mixed DTR modes

From: Miquel Raynal

Date: Fri Nov 27 2026 - 09:23:59 EST


The following operations are supported:
- S-S-D
- S-D-D
- D-D-D
But the following are not:
- S-D-S
- D-D-S
- D-S-S

Make sure these cases are refused by the core.

Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>
---
drivers/spi/spi-mem.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 3989017dd86f..25f795d5e9ba 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -195,6 +195,27 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
return false;
}

+ /* xD-xS-xS is not allowed */
+ if (op->cmd.dtr) {
+ if ((op->addr.nbytes && !op->addr.dtr) ||
+ (op->dummy.nbytes && !op->dummy.dtr) ||
+ (op->data.nbytes && !op->data.dtr))
+ return false;
+ }
+
+ /* xS-xD-xS is not allowed */
+ if (op->addr.nbytes && op->addr.dtr) {
+ if ((op->dummy.nbytes && !op->dummy.dtr) ||
+ (op->data.nbytes && !op->data.dtr))
+ return false;
+ }
+
+ /* xS-xS-xD-xS is not allowed */
+ if (op->dummy.nbytes && op->dummy.dtr) {
+ if (op->data.nbytes && !op->data.dtr)
+ return false;
+ }
+
if (op->data.ecc) {
if (!spi_mem_controller_is_capable(ctlr, ecc))
return false;

--
2.56.0