Skip to content

Commit 4ceaa68

Browse files
marckleinebuddebroonie
authored andcommitted
spi: bcm2835: bcm2835_spi_handle_err(): fix NULL pointer deref for non DMA transfers
In case a IRQ based transfer times out the bcm2835_spi_handle_err() function is called. Since commit 1513cee ("spi: bcm2835: Drop dma_pending flag") the TX and RX DMA transfers are unconditionally canceled, leading to NULL pointer derefs if ctlr->dma_tx or ctlr->dma_rx are not set. Fix the NULL pointer deref by checking that ctlr->dma_tx and ctlr->dma_rx are valid pointers before accessing them. Fixes: 1513cee ("spi: bcm2835: Drop dma_pending flag") Cc: Lukas Wunner <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 73d5fe0 commit 4ceaa68

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/spi/spi-bcm2835.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,14 @@ static void bcm2835_spi_handle_err(struct spi_controller *ctlr,
11381138
struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
11391139

11401140
/* if an error occurred and we have an active dma, then terminate */
1141-
dmaengine_terminate_sync(ctlr->dma_tx);
1142-
bs->tx_dma_active = false;
1143-
dmaengine_terminate_sync(ctlr->dma_rx);
1144-
bs->rx_dma_active = false;
1141+
if (ctlr->dma_tx) {
1142+
dmaengine_terminate_sync(ctlr->dma_tx);
1143+
bs->tx_dma_active = false;
1144+
}
1145+
if (ctlr->dma_rx) {
1146+
dmaengine_terminate_sync(ctlr->dma_rx);
1147+
bs->rx_dma_active = false;
1148+
}
11451149
bcm2835_spi_undo_prologue(bs);
11461150

11471151
/* and reset */

0 commit comments

Comments
 (0)