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 1513ceee70f2 ("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: 1513ceee70f2 ("spi: bcm2835: Drop dma_pending flag")
Cc: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/r/20220719072234.2782764-1-mkl@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Marc Kleine-Budde and committed by
Mark Brown
4ceaa684 73d5fe04

+8 -4
+8 -4
drivers/spi/spi-bcm2835.c
··· 1138 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); 1139 1140 /* 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; 1145 bcm2835_spi_undo_prologue(bs); 1146 1147 /* and reset */
··· 1138 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); 1139 1140 /* if an error occurred and we have an active dma, then terminate */ 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 + } 1149 bcm2835_spi_undo_prologue(bs); 1150 1151 /* and reset */