From c0eaf1266158d473931ae3db5dfcda0bbaf493c2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 7 Jan 2025 15:44:21 +0900 Subject: [PATCH] esp32s3_wifi_adapter.c: Fix a deadlock Fixes: https://github.com/apache/nuttx/issues/15314 --- arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c b/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c index 468eacaa25..5f3e6274b7 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c +++ b/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c @@ -2125,6 +2125,13 @@ static void esp_evt_work_cb(void *arg) break; } + /* Some of the following logic (eg. esp32s3_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) @@ -2268,6 +2275,7 @@ static void esp_evt_work_cb(void *arg) } esp_wifi_lock(false); + net_unlock(); kmm_free(evt_adpt); }