[PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 27 06:43:03 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: spi-mem: missing dummy.ncycles checks in
spi_mem_default_supports_op()
--
commit 5399654721195bff49303bc619a04db290c22c52
Author: Miquel Raynal <miquel.raynal at bootlin.com>
spi: spi-mem: Add support for dummy cycles
This commit adds a dummy.ncycles field to struct spi_mem_op and a
dummy_cycles capability to struct spi_controller_mem_caps, converting
between dummy bytes and dummy clock cycles depending on controller
capabilities.
Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/
Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index a1f129c476984..1642388b70048 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
[ ... ]
> +/*
> + * Controllers either program the dummy phase in clock cycles or in whole
> + * bytes. Convert the representation used by the operation to the one the
> + * controller expects.
> + *
> + * Return: 0 if the operation is lossless, -EOPNOTSUPP otherwise.
> + */
> +static int spi_mem_convert_dummy(struct spi_mem *mem, struct spi_mem_op *op)
> +{
> + struct spi_controller *ctlr = mem->spi->controller;
> + int n;
> +
> + if (op->dummy.ncycles) {
> + if (spi_mem_controller_is_capable(ctlr, dummy_cycles))
> + return 0;
> +
> + n = spi_mem_dummy_cycles_to_bytes(op);
> + if (n < 0)
> + return n;
> +
> + op->dummy.nbytes = n;
> + op->dummy.ncycles = 0;
> + } else if (op->dummy.nbytes) {
> + if (!spi_mem_controller_is_capable(ctlr, dummy_cycles))
> + return 0;
> +
> + n = spi_mem_dummy_bytes_to_cycles(op);
> + if (n < 0)
> + return n;
> +
> + op->dummy.ncycles = n;
> + op->dummy.nbytes = 0;
> +
> + return 0;
> + }
> +
> + return 0;
> +}
[ ... ]
> @@ -321,6 +448,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
> if (spi_mem_check_op(&eval_op))
> return false;
>
> + if (spi_mem_convert_dummy(mem, &eval_op))
> + return false;
> +
> return spi_mem_internal_supports_op(mem, &eval_op);
> }
> EXPORT_SYMBOL_GPL(spi_mem_supports_op);
[Severity: Medium]
Should spi_mem_default_supports_op() also check op->dummy.ncycles in its
dummy-phase DTR and buswidth checks?
When a controller advertises dummy_cycles, spi_mem_convert_dummy() leaves
the dummy duration in op->dummy.ncycles with op->dummy.nbytes set to 0
before spi_mem_supports_op() and spi_mem_exec_op() call
spi_mem_internal_supports_op(). Because spi_mem_default_supports_op() only
tests op->dummy.nbytes:
drivers/spi/spi-mem.c:spi_mem_default_supports_op() {
...
/* xS-xS-xD-xS is not allowed */
if (op->dummy.nbytes && op->dummy.dtr) {
if (op->data.nbytes && !op->data.dtr)
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;
...
}
those checks are skipped whenever op->dummy.ncycles is used, allowing
operations with invalid DTR transitions or decreasing buswidth across the
dummy phase to pass spi_mem_supports_op() and reach controller execution.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=6
More information about the linux-mtd
mailing list