From 9962cc9c9f4e6ca146ebdc9ae4dc02bbdfa4024b Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Mon, 8 May 2017 16:11:46 +0800 Subject: [PATCH] Fix out-of-bounds on dmaworkaround_channels_busy --- components/driver/spi_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/driver/spi_common.c b/components/driver/spi_common.c index d58d202d3..9f2d8ac76 100644 --- a/components/driver/spi_common.c +++ b/components/driver/spi_common.c @@ -350,7 +350,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t int otherchan = (dmachan == 1) ? 2 : 1; bool ret; portENTER_CRITICAL(&dmaworkaround_mux); - if (dmaworkaround_channels_busy[otherchan]) { + if (dmaworkaround_channels_busy[otherchan-1]) { //Other channel is busy. Call back when it's done. dmaworkaround_cb = cb; dmaworkaround_cb_arg = arg; @@ -374,7 +374,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_reset_in_progress() void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan) { portENTER_CRITICAL(&dmaworkaround_mux); - dmaworkaround_channels_busy[dmachan] = 0; + dmaworkaround_channels_busy[dmachan-1] = 0; if (dmaworkaround_waiting_for_chan == dmachan) { //Reset DMA SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_DMA_RST); @@ -390,7 +390,7 @@ void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan) void IRAM_ATTR spicommon_dmaworkaround_transfer_active(int dmachan) { portENTER_CRITICAL(&dmaworkaround_mux); - dmaworkaround_channels_busy[dmachan] = 1; + dmaworkaround_channels_busy[dmachan-1] = 1; portEXIT_CRITICAL(&dmaworkaround_mux); }