From 4c3d49e3f083ac9c4114b4ef7d80433f779cd477 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Fri, 20 Dec 2019 21:57:26 +0800 Subject: [PATCH] can: Fix semaphore take in critical section This commit fixes can_reconfigure_alerts() which could lead to a call to xSemaphoreTake() whilst inside a critical section. Closes https://github.com/espressif/esp-idf/issues/4277 --- components/driver/can.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/driver/can.c b/components/driver/can.c index 1dd506568c..209c3183f6 100644 --- a/components/driver/can.c +++ b/components/driver/can.c @@ -958,15 +958,16 @@ esp_err_t can_read_alerts(uint32_t *alerts, TickType_t ticks_to_wait) esp_err_t can_reconfigure_alerts(uint32_t alerts_enabled, uint32_t *current_alerts) { CAN_CHECK(p_can_obj != NULL, ESP_ERR_INVALID_STATE); + CAN_ENTER_CRITICAL(); - uint32_t cur_alerts; - can_read_alerts(&cur_alerts, 0); //Clear any unhandled alerts + //Clear any unhandled alerts + if (current_alerts != NULL) { + *current_alerts = p_can_obj->alerts_triggered;; + } + p_can_obj->alerts_triggered = 0; p_can_obj->alerts_enabled = alerts_enabled; //Update enabled alerts CAN_EXIT_CRITICAL(); - if (current_alerts != NULL) { - *current_alerts = cur_alerts; - } return ESP_OK; }