diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_adapter.c index 504499d89e197..33bf1a06831e6 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_adapter.c @@ -2257,6 +2257,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp32c3_wlan_sta_set_linkstatus) + * can take net_lock(). To maintain the consistent locking order, + * we take net_lock() here before taking esp_wifi_lock. Note that + * net_lock() is a recursive lock. + */ + + net_lock(); esp_wifi_lock(true); switch (evt_adpt->id) @@ -2397,6 +2404,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); }