This is an automated email from the ASF dual-hosted git repository. masayuki pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 18d74dbea0bc151c34e3751089229c537743cea2 Author: Gustavo Henrique Nihei <gustavo.ni...@espressif.com> AuthorDate: Tue May 24 12:49:03 2022 -0300 risc-v/esp32c3: Fix leak of semaphores created by Wi-Fi kernel thread Signed-off-by: Gustavo Henrique Nihei <gustavo.ni...@espressif.com> --- arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c | 34 ++++++++++++---------- .../esp32c3-devkit/configs/autopm/defconfig | 1 + .../esp32c3-devkit/configs/sta_softap/defconfig | 1 + .../esp32c3/esp32c3-devkit/configs/wapi/defconfig | 1 + 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index 5fa785a2e7..d12d054dc3 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -49,6 +49,7 @@ #include <nuttx/signal.h> #include <nuttx/arch.h> #include <nuttx/wireless/wireless.h> +#include <nuttx/tls.h> #include "riscv_internal.h" @@ -1333,35 +1334,36 @@ static int IRAM_ATTR wifi_is_in_isr(void) static void *esp_thread_semphr_get(void) { + static int wifi_task_key = -1; int ret; void *sem; - if (g_wifi_tkey_init) - { - ret = pthread_key_create(&g_wifi_thread_key, esp_thread_semphr_free); - if (ret) - { - wlerr("ERROR: Failed to create pthread key\n"); - return NULL; - } + if (wifi_task_key < 0) + { + ret = task_tls_alloc(esp_thread_semphr_free); + if (ret < 0) + { + wlerr("Failed to create task local key\n"); + return NULL; + } - g_wifi_tkey_init = true; - } + wifi_task_key = ret; + } - sem = pthread_getspecific(g_wifi_thread_key); - if (!sem) + sem = (void *)task_tls_get_value(wifi_task_key); + if (sem == NULL) { sem = esp_semphr_create(1, 0); if (!sem) { - wlerr("ERROR: Failed to create semaphore\n"); + wlerr("Failed to create semaphore\n"); return NULL; } - ret = pthread_setspecific(g_wifi_thread_key, sem); - if (ret) + ret = task_tls_set_value(wifi_task_key, (uintptr_t)sem); + if (ret != OK) { - wlerr("ERROR: Failed to set specific\n"); + wlerr("Failed to save semaphore on task local storage: %d\n", ret); esp_semphr_delete(sem); return NULL; } diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig index ac1a7b1ccd..eade6df08a 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig +++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig @@ -60,6 +60,7 @@ CONFIG_START_YEAR=2011 CONFIG_SYSTEM_DHCPC_RENEW=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_PING=y +CONFIG_TLS_TASK_NELEM=4 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_WIRELESS=y CONFIG_WIRELESS_WAPI=y diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig index 0ce646eb70..b3f9a95acd 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig +++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig @@ -74,6 +74,7 @@ CONFIG_START_YEAR=2011 CONFIG_SYSTEM_DHCPC_RENEW=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_PING=y +CONFIG_TLS_TASK_NELEM=4 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_WIRELESS=y CONFIG_WIRELESS_WAPI=y diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig index 887b0577a7..82aa22dbb8 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig +++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig @@ -58,6 +58,7 @@ CONFIG_START_YEAR=2011 CONFIG_SYSTEM_DHCPC_RENEW=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_PING=y +CONFIG_TLS_TASK_NELEM=4 CONFIG_UART0_SERIAL_CONSOLE=y CONFIG_WIRELESS=y CONFIG_WIRELESS_WAPI=y