From 4d877abf3f1cf5ef488ce0059ab2947f546e5772 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Nihei Date: Thu, 25 Mar 2021 17:32:06 -0300 Subject: [PATCH] xtensa/esp32: Avoid incrementing a NULL pointer for RX buffer --- arch/xtensa/src/esp32/esp32_spi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_spi.c b/arch/xtensa/src/esp32/esp32_spi.c index 9c3a749cee..cbd29a7a0d 100644 --- a/arch/xtensa/src/esp32/esp32_spi.c +++ b/arch/xtensa/src/esp32/esp32_spi.c @@ -916,6 +916,8 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv, esp32_spi_set_reg(priv, SPI_MOSI_DLEN_OFFSET, bytes * 8 - 1); esp32_spi_set_regbits(priv, SPI_USER_OFFSET, SPI_USR_MOSI_M); + tp += n; + if (rp) { esp32_dma_init(s_dma_rxdesc[priv->config->dma_chan - 1], @@ -927,6 +929,8 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv, regval | SPI_INLINK_START_M); esp32_spi_set_reg(priv, SPI_MISO_DLEN_OFFSET, bytes * 8 - 1); esp32_spi_set_regbits(priv, SPI_USER_OFFSET, SPI_USR_MISO_M); + + rp += n; } else { @@ -938,8 +942,6 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv, esp32_spi_sem_waitdone(priv); bytes -= n; - tp += n; - rp += n; } esp32_spi_reset_regbits(priv, SPI_SLAVE_OFFSET, SPI_INT_EN_M);