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); } diff --git a/arch/risc-v/src/esp32c3/esp_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp_wifi_adapter.c index 44fa965b641e4..533fb7c0b2063 100644 --- a/arch/risc-v/src/esp32c3/esp_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp_wifi_adapter.c @@ -2576,6 +2576,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp_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) @@ -2697,6 +2704,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); } diff --git a/arch/risc-v/src/esp32c6/esp_wifi_adapter.c b/arch/risc-v/src/esp32c6/esp_wifi_adapter.c index 271b7473c8106..9d42423a1fe46 100644 --- a/arch/risc-v/src/esp32c6/esp_wifi_adapter.c +++ b/arch/risc-v/src/esp32c6/esp_wifi_adapter.c @@ -2530,6 +2530,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp_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) @@ -2651,6 +2658,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); } diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index 54da5a46393ae..3517ebdceaf27 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -2122,6 +2122,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp32_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) @@ -2265,6 +2272,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); } diff --git a/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c b/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c index 49e3872b3e0d3..85edf437dc415 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c +++ b/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c @@ -2081,6 +2081,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp_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) @@ -2203,6 +2210,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); }