Skip to content

Commit c4f2c05

Browse files
ordexbroonie
authored andcommitted
spi: stm32: fix pointer-to-pointer variables usage
In stm32_spi_prepare_rx_dma_mdma_chaining() both rx_dma_desc and rx_mdma_desc are passed as pointer-to-pointer arguments. The goal is to pass back to the caller the value returned by dmaengine_prep_slave_sg(), when it is not NULL. However, these variables are wrongly handled as simple pointers during later assignments and checks. Fix this behaviour by introducing two pointer variables which can then be treated accordingly. Fixes: d17dd2f ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use") Addresses-Coverity-ID: 1644715 ("Null pointer dereferences (REVERSE_INULL)") Signed-off-by: Antonio Quartulli <[email protected]> Reviewed-by: Clement LE GOFFIC <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f4d8438 commit c4f2c05

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/spi/spi-stm32.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,8 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
14741474
struct dma_async_tx_descriptor **rx_dma_desc,
14751475
struct dma_async_tx_descriptor **rx_mdma_desc)
14761476
{
1477+
struct dma_async_tx_descriptor *_mdma_desc = *rx_mdma_desc;
1478+
struct dma_async_tx_descriptor *_dma_desc = *rx_dma_desc;
14771479
struct dma_slave_config rx_mdma_conf = {0};
14781480
u32 sram_period, nents = 0, spi_s_len;
14791481
struct sg_table dma_sgt, mdma_sgt;
@@ -1524,18 +1526,18 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
15241526
}
15251527
}
15261528

1527-
*rx_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
1528-
dma_sgt.nents, rx_dma_conf->direction,
1529-
DMA_PREP_INTERRUPT);
1529+
_dma_desc = dmaengine_prep_slave_sg(spi->dma_rx, dma_sgt.sgl,
1530+
dma_sgt.nents, rx_dma_conf->direction,
1531+
DMA_PREP_INTERRUPT);
15301532
sg_free_table(&dma_sgt);
15311533

1532-
if (!rx_dma_desc)
1534+
if (!_dma_desc)
15331535
return -EINVAL;
15341536

15351537
/* Prepare MDMA slave_sg transfer MEM_TO_MEM (SRAM>DDR) */
15361538
ret = sg_alloc_table(&mdma_sgt, nents, GFP_ATOMIC);
15371539
if (ret) {
1538-
rx_dma_desc = NULL;
1540+
_dma_desc = NULL;
15391541
return ret;
15401542
}
15411543

@@ -1558,13 +1560,13 @@ static int stm32_spi_prepare_rx_dma_mdma_chaining(struct stm32_spi *spi,
15581560
}
15591561
}
15601562

1561-
*rx_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
1562-
mdma_sgt.nents, rx_mdma_conf.direction,
1563-
DMA_PREP_INTERRUPT);
1563+
_mdma_desc = dmaengine_prep_slave_sg(spi->mdma_rx, mdma_sgt.sgl,
1564+
mdma_sgt.nents, rx_mdma_conf.direction,
1565+
DMA_PREP_INTERRUPT);
15641566
sg_free_table(&mdma_sgt);
15651567

1566-
if (!rx_mdma_desc) {
1567-
rx_dma_desc = NULL;
1568+
if (!_mdma_desc) {
1569+
_dma_desc = NULL;
15681570
return -EINVAL;
15691571
}
15701572

0 commit comments

Comments
 (0)