[PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops
Bough Chen
haibo.chen at oss.nxp.com
Fri Nov 27 00:46:43 PST 2026
On Wed, Nov 25, 2026 at 06:51:15PM +0100, Miquel Raynal wrote:
> 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 at bootlin.com>
> ---
> 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;
Hi Miquel,
So this change means no nbytes limitation for mixed mode oparations, such as 1S-1D-8D. Is it correct?
I go through spi-nor and spi-nand driver, seems for spi-nor, for DTR mode, it only support 8D-8D-8D mode,
but for spi-nand, I notice some winbond W35N chips did support not only 8D-8D-8D mode, but also some mixed
mode, including 1S-1D-8D. Does this 1S-1D-8D mode really has no such limitation for address and data length?
Address and data are indeed in DTR mode.
Regards
Haibo Chen
> + } 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
>
More information about the linux-riscv
mailing list