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

From: Bough Chen

Date: Mon Nov 30 2026 - 05:25:45 EST


On Fri, Nov 27, 2026 at 03:22:26PM +0100, Miquel Raynal wrote:
> 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 */

better change the comment to xD-xS-xS-xS, add dummy inside.

> + 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 */

Same here.

Regards
Haibo Chen
> + 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
>