[PATCH 2/3] spi: ma35d1-qspi: reschedule during long PIO transfers
From: Miquel Raynal
Date: Wed Nov 18 2026 - 08:55:31 EST
The driver performs every transfer byte by byte in PIO mode, polling the
FIFO status between each byte. Since spi-mem operations can span over an
entire block (128 or 256 kiB), the CPU may be kept in this loop for a
long time.
The spi-mem ->exec_op() path does not go through __spi_pump_messages(),
which is where the SPI core adds a cond_resched() after a transfer. On
kernels without involuntary preemption (unlikely on embedded systems
with this controller, but still), nothing would yield in between. To
avoid keeping the CPU for ourselves for too long in these cases, add a
cond_resched() point every 4 KiB in the data loop.
Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>
---
drivers/spi/spi-ma35d1-qspi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/spi/spi-ma35d1-qspi.c b/drivers/spi/spi-ma35d1-qspi.c
index 1ec631afa403..65dbad6f63c7 100644
--- a/drivers/spi/spi-ma35d1-qspi.c
+++ b/drivers/spi/spi-ma35d1-qspi.c
@@ -328,6 +328,9 @@ static int nuvoton_qspi_txrx(struct nuvoton_qspi *qspi, const void *txbuf,
val = nuvoton_qspi_read(qspi, NUVOTON_QSPI_RX_OFFSET);
if (rxbuf)
nuvoton_qspi_rx_byte(rxbuf, i, val);
+
+ if (i && !(i % NUVOTON_QSPI_MAX_TRANSFER_SIZE))
+ cond_resched();
}
ret = nuvoton_qspi_wait_ready(qspi);
--
2.56.0