[PATCH RFC v2 03/35] spi: spi-mem: Handle a corner case while sanitizing ops

Bough Chen haibo.chen at oss.nxp.com
Mon Nov 30 02:25:03 PST 2026


On Fri, Nov 27, 2026 at 03:22:25PM +0100, Miquel Raynal wrote:
> Mixed DTR operations (eg. 1S-xD-yD) set op_is_dtr but do not enter the
> ODTR checks, so their command size is never validated.
> 
> Always check the command size: one byte, or two bytes in ODTR mode.
> Require an even byte count only on 8-bit DTR phases, which carry two
> bytes per clock cycle. Narrower DTR phases may use odd counts.
> 
> Regarding the dummy phase, either the controller is only supporting
> "bytes", in which case the check must be performed, or (soon) they might
> advertize the dummy_cycles capability for which sending an even number
> of dummy bytes is irrelevant. The check can remain though, since in this
> case dummy.nbytes will be 0 (those values are mutually exclusive, the
> core will check that).
> 
> Fixes: 8618271887ca ("spi: spi-mem: Limit octal DTR constraints to octal DTR situations")
> Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>

Reviewed-by: Haibo Chen <haibo.chen at nxp.com>

Regards
Haibo Chen
> ---
>  drivers/spi/spi-mem.c | 28 +++++++++++++---------------
>  1 file changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index f4d71f740163..3989017dd86f 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -171,6 +171,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)
> @@ -178,23 +179,20 @@ 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;
> +	/* Command phase is single byte, except in ODTR mode where it is two */
> +	if ((!op_is_odtr && op->cmd.nbytes != 1) ||
> +	    (op_is_odtr && op->cmd.nbytes != 2))
> +		return false;
>  
> -			if ((op->addr.nbytes % 2) ||
> -			    (op->dummy.nbytes % 2) ||
> -			    (op->data.nbytes % 2)) {
> -				dev_err(&ctlr->dev,
> -					"Odd byte numbers not allowed in octal DTR operations\n");
> -				return false;
> -			}
> -		}
> -	} else {
> -		if (op->cmd.nbytes != 1)
> -			return false;
> +	/* ODTR phases shall carry even byte numbers */
> +	if ((op->addr.dtr && op->addr.buswidth == 8 && op->addr.nbytes % 2) ||
> +	    (op->dummy.dtr && op->dummy.buswidth == 8 && op->dummy.nbytes % 2) ||
> +	    (op->data.dtr && op->data.buswidth == 8 && op->data.nbytes % 2)) {
> +		dev_err(&ctlr->dev,
> +			"Odd byte numbers not allowed in octal DTR phases\n");
> +		return false;
>  	}
>  
>  	if (op->data.ecc) {
> 
> -- 
> 2.56.0
> 



More information about the linux-arm-kernel mailing list