From 9e7882ba6dc3deaca2546a4a83e3b4b45424a4f3 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Tue, 18 Jul 2023 23:26:46 +0800 Subject: [PATCH] fix(gpio): fix potential crash when processing gpio isr If CONFIG_SPIRAM_USE_MALLOC is enabled, and cache is disabled when GPIO ISR is triggered, it would lead to Guru Meditation Error due to "Cache disabled but cached memory region accessed". Closes https://github.com/espressif/esp-idf/issues/11876 --- components/driver/gpio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/driver/gpio.c b/components/driver/gpio.c index d886d32418..c193b6fe3c 100644 --- a/components/driver/gpio.c +++ b/components/driver/gpio.c @@ -15,6 +15,7 @@ #include #include "esp_err.h" #include "freertos/FreeRTOS.h" +#include "esp_heap_caps.h" #include "driver/gpio.h" #include "driver/rtc_io.h" #include "soc/soc.h" @@ -459,8 +460,9 @@ esp_err_t gpio_install_isr_service(int intr_alloc_flags) { GPIO_CHECK(gpio_context.gpio_isr_func == NULL, "GPIO isr service already installed", ESP_ERR_INVALID_STATE); esp_err_t ret; + const uint32_t alloc_caps = (intr_alloc_flags & ESP_INTR_FLAG_IRAM) ? MALLOC_CAP_INTERNAL : MALLOC_CAP_DEFAULT; portENTER_CRITICAL(&gpio_context.gpio_spinlock); - gpio_context.gpio_isr_func = (gpio_isr_func_t *) calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t)); + gpio_context.gpio_isr_func = (gpio_isr_func_t *) heap_caps_calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t), alloc_caps); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); if (gpio_context.gpio_isr_func == NULL) { ret = ESP_ERR_NO_MEM;