]> granicus.if.org Git - esp-idf/commitdiff
fix(spi_master): fix the heap corruption bug that RX DMA writes over the temporary...
authormichael <xiaoxufeng@espressif.com>
Fri, 15 Sep 2017 08:19:11 +0000 (16:19 +0800)
committermichael <xiaoxufeng@espressif.com>
Tue, 19 Sep 2017 08:47:14 +0000 (16:47 +0800)
TW#15434

Closes #994.

components/driver/spi_master.c

index dc073dc28836f4442029c143953506c0abe8a845..465f0689949b8f29d351c02ad63887621f56423e 100644 (file)
@@ -620,8 +620,8 @@ esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *
         trans_buf.buffer_to_rcv = trans_desc->rx_buffer;
     }
     if ( trans_buf.buffer_to_rcv && handle->host->dma_chan && (!esp_ptr_dma_capable( trans_buf.buffer_to_rcv ) || ((int)trans_buf.buffer_to_rcv%4!=0)) ) {
-        //if rxbuf in the desc not DMA-capable, malloc a new one
-        trans_buf.buffer_to_rcv = heap_caps_malloc((trans_desc->rxlength+7)/8, MALLOC_CAP_DMA);
+        //if rxbuf in the desc not DMA-capable, malloc a new one. The rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
+        trans_buf.buffer_to_rcv = heap_caps_malloc((trans_desc->rxlength+31)/8, MALLOC_CAP_DMA);
         if ( trans_buf.buffer_to_rcv==NULL ) return ESP_ERR_NO_MEM;
     }