OSDN Git Service

spi: sun6i: fix race between DMA RX transfer completion and RX FIFO drain
authorTobias Schramm <t.schramm@manjaro.org>
Sun, 27 Aug 2023 15:25:58 +0000 (17:25 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 4 Sep 2023 12:55:29 +0000 (13:55 +0100)
commit1f11f4202caf5710204d334fe63392052783876d
tree0f34f68f251d768240bdda14b6708902a0377ae4
parent171f8a49f212e87a8b04087568e1b3d132e36a18
spi: sun6i: fix race between DMA RX transfer completion and RX FIFO drain

Previously the transfer complete IRQ immediately drained to RX FIFO to
read any data remaining in FIFO to the RX buffer. This behaviour is
correct when dealing with SPI in interrupt mode. However in DMA mode the
transfer complete interrupt still fires as soon as all bytes to be
transferred have been stored in the FIFO. At that point data in the FIFO
still needs to be picked up by the DMA engine. Thus the drain procedure
and DMA engine end up racing to read from RX FIFO, corrupting any data
read. Additionally the RX buffer pointer is never adjusted according to
DMA progress in DMA mode, thus calling the RX FIFO drain procedure in DMA
mode is a bug.
Fix corruptions in DMA RX mode by draining RX FIFO only in interrupt mode.
Also wait for completion of RX DMA when in DMA mode before returning to
ensure all data has been copied to the supplied memory buffer.

Signed-off-by: Tobias Schramm <t.schramm@manjaro.org>
Link: https://lore.kernel.org/r/20230827152558.5368-3-t.schramm@manjaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-sun6i.c