Commit e82b0b38 authored by Lukas Wunner's avatar Lukas Wunner Committed by Mark Brown

spi: bcm2835: Fix race on DMA termination

If a DMA transfer finishes orderly right when spi_transfer_one_message()
determines that it has timed out, the callbacks bcm2835_spi_dma_done()
and bcm2835_spi_handle_err() race to call dmaengine_terminate_all(),
potentially leading to double termination.

Prevent by atomically changing the dma_pending flag before calling
dmaengine_terminate_all().
Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
Fixes: 3ecd37ed ("spi: bcm2835: enable dma modes for transfers meeting certain conditions")
Cc: stable@vger.kernel.org # v4.2+
Cc: Mathias Duckeck <m.duckeck@kunbus.de>
Cc: Frank Pavlic <f.pavlic@kunbus.de>
Cc: Martin Sperl <kernel@martin.sperl.org>
Cc: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent dbc94411
...@@ -232,10 +232,9 @@ static void bcm2835_spi_dma_done(void *data) ...@@ -232,10 +232,9 @@ static void bcm2835_spi_dma_done(void *data)
* is called the tx-dma must have finished - can't get to this * is called the tx-dma must have finished - can't get to this
* situation otherwise... * situation otherwise...
*/ */
if (cmpxchg(&bs->dma_pending, true, false)) {
dmaengine_terminate_all(master->dma_tx); dmaengine_terminate_all(master->dma_tx);
}
/* mark as no longer pending */
bs->dma_pending = 0;
/* and mark as completed */; /* and mark as completed */;
complete(&master->xfer_completion); complete(&master->xfer_completion);
...@@ -617,10 +616,9 @@ static void bcm2835_spi_handle_err(struct spi_master *master, ...@@ -617,10 +616,9 @@ static void bcm2835_spi_handle_err(struct spi_master *master,
struct bcm2835_spi *bs = spi_master_get_devdata(master); struct bcm2835_spi *bs = spi_master_get_devdata(master);
/* if an error occurred and we have an active dma, then terminate */ /* if an error occurred and we have an active dma, then terminate */
if (bs->dma_pending) { if (cmpxchg(&bs->dma_pending, true, false)) {
dmaengine_terminate_all(master->dma_tx); dmaengine_terminate_all(master->dma_tx);
dmaengine_terminate_all(master->dma_rx); dmaengine_terminate_all(master->dma_rx);
bs->dma_pending = 0;
} }
/* and reset */ /* and reset */
bcm2835_spi_reset_hw(master); bcm2835_spi_reset_hw(master);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment