aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCezary Gapinski <cezary.gapinski@gmail.com>2018-12-24 17:00:29 -0500
committerMark Brown <broonie@kernel.org>2019-01-07 13:23:56 -0500
commit2cbee7f886b2ab6b723745b295379ec6475f2ee3 (patch)
tree2fb9a964a80a2d30690b35298aaa5335fe4aae87
parentd4c9134a6c2c85d18b0d58accdf0e9be447f77a3 (diff)
spi: stm32: fix DMA configuration with only one channel
When SPI driver is configured to work only with TX or RX DMA channel then dmaengine functions can dereferene NULL pointer. Running full-duplex mode when when only RX or TX DMA channel is available can cause overrun condition or incorrect writing to transmit buffer so disable this types of DMA configuration and go back to interrupt mode. Signed-off-by: Cezary Gapinski <cezary.gapinski@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-stm32.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 51d7f720127b..8310f14fe273 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -427,9 +427,9 @@ static void stm32_spi_disable(struct stm32_spi *spi)
427 if (!spi->cur_usedma && spi->rx_buf && (spi->rx_len > 0)) 427 if (!spi->cur_usedma && spi->rx_buf && (spi->rx_len > 0))
428 stm32_spi_read_rxfifo(spi, true); 428 stm32_spi_read_rxfifo(spi, true);
429 429
430 if (spi->cur_usedma && spi->tx_buf) 430 if (spi->cur_usedma && spi->dma_tx)
431 dmaengine_terminate_all(spi->dma_tx); 431 dmaengine_terminate_all(spi->dma_tx);
432 if (spi->cur_usedma && spi->rx_buf) 432 if (spi->cur_usedma && spi->dma_rx)
433 dmaengine_terminate_all(spi->dma_rx); 433 dmaengine_terminate_all(spi->dma_rx);
434 434
435 stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE); 435 stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
@@ -750,7 +750,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
750 spin_lock_irqsave(&spi->lock, flags); 750 spin_lock_irqsave(&spi->lock, flags);
751 751
752 rx_dma_desc = NULL; 752 rx_dma_desc = NULL;
753 if (spi->rx_buf) { 753 if (spi->rx_buf && spi->dma_rx) {
754 stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM); 754 stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM);
755 dmaengine_slave_config(spi->dma_rx, &rx_dma_conf); 755 dmaengine_slave_config(spi->dma_rx, &rx_dma_conf);
756 756
@@ -765,7 +765,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
765 } 765 }
766 766
767 tx_dma_desc = NULL; 767 tx_dma_desc = NULL;
768 if (spi->tx_buf) { 768 if (spi->tx_buf && spi->dma_tx) {
769 stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV); 769 stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV);
770 dmaengine_slave_config(spi->dma_tx, &tx_dma_conf); 770 dmaengine_slave_config(spi->dma_tx, &tx_dma_conf);
771 771
@@ -776,8 +776,11 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
776 DMA_PREP_INTERRUPT); 776 DMA_PREP_INTERRUPT);
777 } 777 }
778 778
779 if ((spi->tx_buf && !tx_dma_desc) || 779 if ((spi->tx_buf && spi->dma_tx && !tx_dma_desc) ||
780 (spi->rx_buf && !rx_dma_desc)) 780 (spi->rx_buf && spi->dma_rx && !rx_dma_desc))
781 goto dma_desc_error;
782
783 if (spi->cur_comm == SPI_FULL_DUPLEX && (!tx_dma_desc || !rx_dma_desc))
781 goto dma_desc_error; 784 goto dma_desc_error;
782 785
783 if (rx_dma_desc) { 786 if (rx_dma_desc) {
@@ -822,7 +825,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
822 return 1; 825 return 1;
823 826
824dma_submit_error: 827dma_submit_error:
825 if (spi->rx_buf) 828 if (spi->dma_rx)
826 dmaengine_terminate_all(spi->dma_rx); 829 dmaengine_terminate_all(spi->dma_rx);
827 830
828dma_desc_error: 831dma_desc_error:
@@ -832,6 +835,7 @@ dma_desc_error:
832 835
833 dev_info(spi->dev, "DMA issue: fall back to irq transfer\n"); 836 dev_info(spi->dev, "DMA issue: fall back to irq transfer\n");
834 837
838 spi->cur_usedma = false;
835 return stm32_spi_transfer_one_irq(spi); 839 return stm32_spi_transfer_one_irq(spi);
836} 840}
837 841
@@ -984,7 +988,7 @@ static int stm32_spi_transfer_one(struct spi_master *master,
984 spi->rx_len = spi->rx_buf ? transfer->len : 0; 988 spi->rx_len = spi->rx_buf ? transfer->len : 0;
985 989
986 spi->cur_usedma = (master->can_dma && 990 spi->cur_usedma = (master->can_dma &&
987 stm32_spi_can_dma(master, spi_dev, transfer)); 991 master->can_dma(master, spi_dev, transfer));
988 992
989 ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer); 993 ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer);
990 if (ret) { 994 if (ret) {