Re: [PATCH RFC v2 05/35] spi: spi-mem: Sanitize mixed buswidth

From: Bough Chen

Date: Mon Nov 30 2026 - 05:29:20 EST


On Fri, Nov 27, 2026 at 03:22:27PM +0100, Miquel Raynal wrote:
> Buswidth is allowed to evolve over phases. Many controllers strictly
> apply the settings passed by the core. In practice for an X-Y-Z
> operation where X, Y and Z represent the buswidth of the command,
> address and data phase, respectively. We do not support:
> - Y < X
> - Z < Y
> - Z < X
>
> Make sure those conditions are sanitized early by the core, to avoid the
> feeling that these needs to be checked in controller drivers. The
> implementation also covers the dummy.nbytes case with the same logic.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>

Reviewed-by: Haibo Chen <haibo.chen@xxxxxxx>

Regards
Haibo Chen
> ---
> drivers/spi/spi-mem.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 25f795d5e9ba..a1f129c47698 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -216,6 +216,15 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
> return false;
> }
>
> + /* Bus width can only grow across phases, ie. 1-4-1, or 1-8-4 are not allowed */
> + if ((op->addr.nbytes && op->addr.buswidth < op->cmd.buswidth) ||
> + (op->dummy.nbytes && op->dummy.buswidth < op->cmd.buswidth) ||
> + (op->data.nbytes && op->data.buswidth < op->cmd.buswidth) ||
> + (op->addr.nbytes && op->dummy.nbytes && op->dummy.buswidth < op->addr.buswidth) ||
> + (op->addr.nbytes && op->data.nbytes && op->data.buswidth < op->addr.buswidth) ||
> + (op->dummy.nbytes && op->data.nbytes && op->data.buswidth < op->dummy.buswidth))
> + return false;
> +
> if (op->data.ecc) {
> if (!spi_mem_controller_is_capable(ctlr, ecc))
> return false;
>
> --
> 2.56.0
>