Re: [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops

From: Miquel Raynal

Date: Fri Nov 27 2026 - 04:18:51 EST


Hello,

> 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@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;
>
> 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.

That is a very good point. I don't think the sanitizer ever did check
that though. I believe we should in the end have a more "per-phase"
approach, where we check all these individually.

There is also an implicit assumption that buswidth will only increase
(eg not 1-4-1) and DTR capability will not disappear (eg no S-D-S).

I guess we need to add more patches to make all these situations covered
and avoid having drivers checking for them.

Thanks,
Miquèl