Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_gpio_driver_calloc_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
fix(gpio): fix potential crash when processing gpio isr (v5.1)

See merge request espressif/esp-idf!24901
  • Loading branch information
jack0c committed Aug 3, 2023
2 parents afcf3e2 + 125014d commit a56ea11
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/driver/gpio/gpio.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <esp_types.h>
#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"
Expand Down Expand Up @@ -497,7 +498,8 @@ 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 = ESP_ERR_NO_MEM;
gpio_isr_func_t *isr_func = (gpio_isr_func_t *) calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t));
const uint32_t alloc_caps = (intr_alloc_flags & ESP_INTR_FLAG_IRAM) ? MALLOC_CAP_INTERNAL : MALLOC_CAP_DEFAULT;
gpio_isr_func_t *isr_func = (gpio_isr_func_t *) heap_caps_calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t), alloc_caps);
if (isr_func) {
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
if (gpio_context.gpio_isr_func == NULL) {
Expand Down

0 comments on commit a56ea11

Please sign in to comment.