[PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops
From: Miquel Raynal
Date: Wed Nov 25 2026 - 12:52:02 EST
Some mixed mode operations (such as 1S-xD-yD) will be flagged with
op_is_dtr but will not enter the ODTR checks. As a result, the number of
command bytes will never be checked.
Reorganize a little bit this helper:
- If the operation contains a DTR phase, sanitize it.
- Then sanitize the op, should it be:
- ODTR (8D-8D-8D)
- anything else
Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>
---
drivers/spi/spi-mem.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 8047b7508c8d..c64e906ba919 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -170,6 +170,7 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
struct spi_controller *ctlr = mem->spi->controller;
bool op_is_dtr =
op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
+ bool op_is_odtr = op->cmd.dtr && op->cmd.buswidth == 8;
if (op_is_dtr) {
if (!spi_mem_controller_is_capable(ctlr, dtr) && !ctlr->dtr_caps)
@@ -177,23 +178,22 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
if (op->data.swap16 && !spi_mem_controller_is_capable(ctlr, swap16))
return false;
+ }
- /* Extra 8D-8D-8D limitations */
- if (op->cmd.dtr && op->cmd.buswidth == 8) {
- if (op->cmd.nbytes != 2)
- return false;
-
- if ((op->addr.nbytes % 2) ||
- (op->dummy.nbytes % 2) ||
- (op->data.nbytes % 2)) {
- dev_err(&ctlr->dev,
- "Even byte numbers not allowed in octal DTR operations\n");
- return false;
- }
- }
- } else {
+ if (!op_is_odtr) {
if (op->cmd.nbytes != 1)
return false;
+ } else {
+ if (op->cmd.nbytes != 2)
+ return false;
+
+ if ((op->addr.nbytes % 2) ||
+ (op->dummy.nbytes % 2) ||
+ (op->data.nbytes % 2)) {
+ dev_err(&ctlr->dev,
+ "Even byte numbers not allowed in octal DTR operations\n");
+ return false;
+ }
}
if (op->data.ecc) {
--
2.56.0