Skip to content

Commit

Permalink
spi: stm32: fix potential dereference null return value
Browse files Browse the repository at this point in the history
This patch fixes the usage of rx_dma_desc and tx_dma_desc pointers
returned by dmaengine_prep_slave_sg, which can be null.

Detected by CoverityScan, CID#1446587 ("Dereference null return value")

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Amelie Delaunay authored and Mark Brown committed Jun 28, 2017
1 parent c67ad36 commit 7b821a6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions drivers/spi/spi-stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,6 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
xfer->rx_sg.nents,
rx_dma_conf.direction,
DMA_PREP_INTERRUPT);

rx_dma_desc->callback = stm32_spi_dma_cb;
rx_dma_desc->callback_param = spi;
}

tx_dma_desc = NULL;
Expand All @@ -790,18 +787,16 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
xfer->tx_sg.nents,
tx_dma_conf.direction,
DMA_PREP_INTERRUPT);

if (spi->cur_comm == SPI_SIMPLEX_TX) {
tx_dma_desc->callback = stm32_spi_dma_cb;
tx_dma_desc->callback_param = spi;
}
}

if ((spi->tx_buf && !tx_dma_desc) ||
(spi->rx_buf && !rx_dma_desc))
goto dma_desc_error;

if (rx_dma_desc) {
rx_dma_desc->callback = stm32_spi_dma_cb;
rx_dma_desc->callback_param = spi;

if (dma_submit_error(dmaengine_submit(rx_dma_desc))) {
dev_err(spi->dev, "Rx DMA submit failed\n");
goto dma_desc_error;
Expand All @@ -811,6 +806,11 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
}

if (tx_dma_desc) {
if (spi->cur_comm == SPI_SIMPLEX_TX) {
tx_dma_desc->callback = stm32_spi_dma_cb;
tx_dma_desc->callback_param = spi;
}

if (dma_submit_error(dmaengine_submit(tx_dma_desc))) {
dev_err(spi->dev, "Tx DMA submit failed\n");
goto dma_submit_error;
Expand Down

0 comments on commit 7b821a6

Please sign in to comment.