spi: dw: fix race between transfer IRQ handler and timeout handler
PATCH v2 1/1 spi: dw: fix race between transfer IRQ handler and timeout handler
On SMP systems, dw_spi_handle_err() can be called from the SPI core kthread while the IRQ handler is still accessing the FIFO on another CPU. Resetting the chip via dw_spi_reset_chip() during an active FIFO read/write causes a bus error.
Fix this by calling disable_irq() before the chip reset, which masks the IRQ and waits for any in-flight handler to complete via synchronize_irq(). This ensures no handler is accessing the FIFO when the reset occurs.
---
v1 -> v2:
- Replace spinlock with disable_irq()/enable_irq() as suggested by Jonathan Chocron. This avoids touching the IRQ handler hot path entirely.
v1: https://lore.kernel.org/linux-spi/[email protected]/
drivers/spi/spi-dw-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi-dw-core.c +2 -0
@@ -468,10 +468,12 @@ static inline void dw_spi_abort(struct spi_controller *ctlr) {struct dw_spi *dws =spi_controller_get_devdata (ctlr);if (dws->dma_mapped) dws->dma_ops->dma_stop (dws); +disable_irq (dws->irq);dw_spi_reset_chip (dws); +enable_irq (dws->irq); } static void dw_spi_handle_err(struct spi_controller *ctlr,
Signature · 1 line
2.40.1
Mark Brown
maintainerQuoted 3 lines · Peng Yang
Fixes 0b6bfad4cee4 ("spi: spi-dw: Remove extraneous locking")Signed-off-by Peng Yang <[email protected]>Suggested-by Jonathan Chocron <[email protected]>
Your signoff doesn't match your email address here, please see Documentation/process/submitting-patches.rst for details on what this is and why it's important.