Skip to content

Commit b722e6f

Browse files
committed
gpio: Bugfix - Move esp_intr_free() out of the critical section in gpio_uninstall_isr_service()
Closes #5571 Fix the bug that if the API was called from one core to free the interrupt source on the other core, it would trigger interrupt watchdog. (cherry picked from commit 0e8286c)
1 parent 81861d0 commit b722e6f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

components/driver/gpio.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,21 @@ esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num)
491491

492492
void gpio_uninstall_isr_service(void)
493493
{
494+
gpio_isr_func_t *gpio_isr_func_free = NULL;
495+
gpio_isr_handle_t gpio_isr_handle_free = NULL;
496+
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
494497
if (gpio_context.gpio_isr_func == NULL) {
498+
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
495499
return;
496500
}
497-
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
498-
esp_intr_free(gpio_context.gpio_isr_handle);
499-
free(gpio_context.gpio_isr_func);
501+
gpio_isr_func_free = gpio_context.gpio_isr_func;
500502
gpio_context.gpio_isr_func = NULL;
503+
gpio_isr_handle_free = gpio_context.gpio_isr_handle;
504+
gpio_context.gpio_isr_handle = NULL;
501505
gpio_context.isr_core_id = GPIO_ISR_CORE_ID_UNINIT;
502506
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
507+
esp_intr_free(gpio_isr_handle_free);
508+
free(gpio_isr_func_free);
503509
return;
504510
}
505511

@@ -532,7 +538,12 @@ esp_err_t gpio_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags,
532538
#else /* CONFIG_FREERTOS_UNICORE */
533539
ret = esp_ipc_call_blocking(gpio_context.isr_core_id, gpio_isr_register_on_core_static, (void *)&p);
534540
#endif /* !CONFIG_FREERTOS_UNICORE */
535-
if(ret != ESP_OK || p.ret != ESP_OK) {
541+
if (ret != ESP_OK) {
542+
ESP_LOGE(GPIO_TAG, "esp_ipc_call_blocking failed (0x%x)", ret);
543+
return ESP_ERR_NOT_FOUND;
544+
}
545+
if (p.ret != ESP_OK) {
546+
ESP_LOGE(GPIO_TAG, "esp_intr_alloc failed (0x%x)", p.ret);
536547
return ESP_ERR_NOT_FOUND;
537548
}
538549
return ESP_OK;

0 commit comments

Comments
 (0)