You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/05/25 00:46:37 UTC

[incubator-nuttx] branch master updated (4b308f6cbd -> b4392f7323)

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


    from 4b308f6cbd mutex/recursive: minor style fix
     new b2d77c0e9c Revert "risc-v/esp32c3: Use onexit to free thread private semaphore"
     new 18d74dbea0 risc-v/esp32c3: Fix leak of semaphores created by Wi-Fi kernel thread
     new b4392f7323 xtensa/esp32: Fix leak of semaphores created by Wi-Fi kernel thread

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c     | 37 ++++++++++------------
 arch/xtensa/src/esp32/esp32_wifi_adapter.c         | 37 ++++++++++------------
 .../esp32c3-devkit/configs/autopm/defconfig        |  2 +-
 .../esp32c3-devkit/configs/sta_softap/defconfig    |  2 +-
 .../esp32c3/esp32c3-devkit/configs/wapi/defconfig  |  2 +-
 .../esp32/esp32-devkitc/configs/autopm/defconfig   |  1 +
 .../esp32/esp32-devkitc/configs/ble/defconfig      |  1 +
 .../esp32/esp32-devkitc/configs/blewifi/defconfig  |  1 +
 .../esp32/esp32-devkitc/configs/coex/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/efuse/defconfig    |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32/esp32-devkitc/configs/mqttc/defconfig    |  1 +
 .../esp32-devkitc/configs/sta_softap/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/wapi/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/wapi_smp/defconfig |  1 +
 .../esp32/esp32-devkitc/configs/wifinsh/defconfig  |  1 +
 .../esp32-ethernet-kit/configs/autopm/defconfig    |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32-ethernet-kit/configs/wapi/defconfig      |  1 +
 .../esp32-wrover-kit/configs/autopm/defconfig      |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32/esp32-wrover-kit/configs/wapi/defconfig  |  1 +
 22 files changed, 53 insertions(+), 44 deletions(-)


[incubator-nuttx] 03/03: xtensa/esp32: Fix leak of semaphores created by Wi-Fi kernel thread

Posted by ma...@apache.org.
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 b4392f7323d4e0a1605118bde510d0d0b8632dc6
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Tue May 24 12:43:38 2022 -0300

    xtensa/esp32: Fix leak of semaphores created by Wi-Fi kernel thread
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_wifi_adapter.c         | 37 ++++++++++------------
 .../esp32/esp32-devkitc/configs/autopm/defconfig   |  1 +
 .../esp32/esp32-devkitc/configs/ble/defconfig      |  1 +
 .../esp32/esp32-devkitc/configs/blewifi/defconfig  |  1 +
 .../esp32/esp32-devkitc/configs/coex/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/efuse/defconfig    |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32/esp32-devkitc/configs/mqttc/defconfig    |  1 +
 .../esp32-devkitc/configs/sta_softap/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/wapi/defconfig     |  1 +
 .../esp32/esp32-devkitc/configs/wapi_smp/defconfig |  1 +
 .../esp32/esp32-devkitc/configs/wifinsh/defconfig  |  1 +
 .../esp32-ethernet-kit/configs/autopm/defconfig    |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32-ethernet-kit/configs/wapi/defconfig      |  1 +
 .../esp32-wrover-kit/configs/autopm/defconfig      |  1 +
 .../configs/mcuboot_update_agent/defconfig         |  1 +
 .../esp32/esp32-wrover-kit/configs/wapi/defconfig  |  1 +
 18 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
index 35792e4d5a..0eca116155 100644
--- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c
+++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
@@ -50,6 +50,7 @@
 #include <nuttx/signal.h>
 #include <nuttx/arch.h>
 #include <nuttx/wireless/wireless.h>
+#include <nuttx/tls.h>
 
 #include "xtensa.h"
 #include "xtensa_attr.h"
@@ -374,11 +375,6 @@ void intr_matrix_set(int cpu_no, uint32_t model_num, uint32_t intr_num);
  * Private Data
  ****************************************************************************/
 
-/* Wi-Fi thread private data */
-
-static pthread_key_t g_wifi_thread_key;
-static bool g_wifi_tkey_init;
-
 /* Wi-Fi event private data */
 
 static struct work_s g_wifi_evt_work;
@@ -1255,23 +1251,24 @@ 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("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)
@@ -1280,10 +1277,10 @@ static void *esp_thread_semphr_get(void)
           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("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/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig
index 7c5449cb96..cb3f50cd52 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig
@@ -71,6 +71,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/xtensa/esp32/esp32-devkitc/configs/ble/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/ble/defconfig
index 851fd3a13d..f0190ef1b8 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/ble/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/ble/defconfig
@@ -56,6 +56,7 @@ CONFIG_START_DAY=6
 CONFIG_START_MONTH=12
 CONFIG_START_YEAR=2011
 CONFIG_SYSTEM_NSH=y
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_BLUETOOTH=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/blewifi/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/blewifi/defconfig
index f11654b366..91b86a877d 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/blewifi/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/blewifi/defconfig
@@ -91,6 +91,7 @@ CONFIG_SYSTEM_PING=y
 CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
 CONFIG_TELNET_CHARACTER_MODE=y
 CONFIG_TELNET_IOTHREAD_STACKSIZE=2048
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_BLUETOOTH=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/coex/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/coex/defconfig
index 75b4de612e..b8c9c38ffe 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/coex/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/coex/defconfig
@@ -129,6 +129,7 @@ CONFIG_SYSTEM_PING=y
 CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
 CONFIG_TELNET_CHARACTER_MODE=y
 CONFIG_TELNET_IOTHREAD_STACKSIZE=2048
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_BLUETOOTH=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/efuse/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/efuse/defconfig
index 6d665cff9f..cccb75ee3e 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/efuse/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/efuse/defconfig
@@ -99,6 +99,7 @@ CONFIG_SYSTEM_STACKMONITOR=y
 CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
 CONFIG_TELNET_CHARACTER_MODE=y
 CONFIG_TELNET_IOTHREAD_STACKSIZE=2048
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_WAPI=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_update_agent/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_update_agent/defconfig
index c2f1daa5bb..9efaef81b3 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_update_agent/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_update_agent/defconfig
@@ -79,6 +79,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/xtensa/esp32/esp32-devkitc/configs/mqttc/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/mqttc/defconfig
index 984282af33..78e334380a 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/mqttc/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/mqttc/defconfig
@@ -77,6 +77,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/xtensa/esp32/esp32-devkitc/configs/sta_softap/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/sta_softap/defconfig
index 6134e4935e..86cf738169 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/sta_softap/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/sta_softap/defconfig
@@ -78,6 +78,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/xtensa/esp32/esp32-devkitc/configs/wapi/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/wapi/defconfig
index e1a37be77e..0f6ad6d11b 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/wapi/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/wapi/defconfig
@@ -96,6 +96,7 @@ CONFIG_SYSTEM_STACKMONITOR=y
 CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
 CONFIG_TELNET_CHARACTER_MODE=y
 CONFIG_TELNET_IOTHREAD_STACKSIZE=2048
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_WAPI=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig
index d97162c393..8cb09e5359 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig
@@ -110,6 +110,7 @@ CONFIG_TELNET_IOTHREAD_STACKSIZE=1280
 CONFIG_TESTING_GETPRIME=y
 CONFIG_TESTING_OSTEST=y
 CONFIG_TESTING_SMP=y
+CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_WIRELESS=y
 CONFIG_WIRELESS_WAPI=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/wifinsh/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/wifinsh/defconfig
index 6edf072afb..388b23b7fb 100644
--- a/boards/xtensa/esp32/esp32-devkitc/configs/wifinsh/defconfig
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/wifinsh/defconfig
@@ -81,6 +81,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/xtensa/esp32/esp32-ethernet-kit/configs/autopm/defconfig b/boards/xtensa/esp32/esp32-ethernet-kit/configs/autopm/defconfig
index 8384a356aa..a5615c3a6a 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/configs/autopm/defconfig
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/configs/autopm/defconfig
@@ -70,6 +70,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/xtensa/esp32/esp32-ethernet-kit/configs/mcuboot_update_agent/defconfig b/boards/xtensa/esp32/esp32-ethernet-kit/configs/mcuboot_update_agent/defconfig
index f15aa3e239..f4572b33a6 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/configs/mcuboot_update_agent/defconfig
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/configs/mcuboot_update_agent/defconfig
@@ -77,6 +77,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/xtensa/esp32/esp32-ethernet-kit/configs/wapi/defconfig b/boards/xtensa/esp32/esp32-ethernet-kit/configs/wapi/defconfig
index bbc40eaa7c..3bca42c539 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/configs/wapi/defconfig
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/configs/wapi/defconfig
@@ -69,6 +69,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/xtensa/esp32/esp32-wrover-kit/configs/autopm/defconfig b/boards/xtensa/esp32/esp32-wrover-kit/configs/autopm/defconfig
index caf877de72..4abbba5996 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/configs/autopm/defconfig
+++ b/boards/xtensa/esp32/esp32-wrover-kit/configs/autopm/defconfig
@@ -71,6 +71,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/xtensa/esp32/esp32-wrover-kit/configs/mcuboot_update_agent/defconfig b/boards/xtensa/esp32/esp32-wrover-kit/configs/mcuboot_update_agent/defconfig
index b09ed2703b..c82577f271 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/configs/mcuboot_update_agent/defconfig
+++ b/boards/xtensa/esp32/esp32-wrover-kit/configs/mcuboot_update_agent/defconfig
@@ -78,6 +78,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/xtensa/esp32/esp32-wrover-kit/configs/wapi/defconfig b/boards/xtensa/esp32/esp32-wrover-kit/configs/wapi/defconfig
index 355d50cc6e..4a9b62bd8b 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/configs/wapi/defconfig
+++ b/boards/xtensa/esp32/esp32-wrover-kit/configs/wapi/defconfig
@@ -70,6 +70,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


[incubator-nuttx] 01/03: Revert "risc-v/esp32c3: Use onexit to free thread private semaphore"

Posted by ma...@apache.org.
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 b2d77c0e9c43b8bb5e95f230c6832bce4a40627a
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Tue May 24 12:41:18 2022 -0300

    Revert "risc-v/esp32c3: Use onexit to free thread private semaphore"
    
    This reverts commit f5eaf82c9338823c9eb1c7a5e083fe37896cb2de.
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c     | 41 +++++++++-------------
 .../esp32c3-devkit/configs/autopm/defconfig        |  1 -
 .../esp32c3-devkit/configs/sta_softap/defconfig    |  1 -
 .../esp32c3/esp32c3-devkit/configs/wapi/defconfig  |  1 -
 4 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c
index 3f80fde166..5fa785a2e7 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c
@@ -38,7 +38,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <irq/irq.h>
-#include <sched/sched.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/mqueue.h>
 #include <nuttx/spinlock.h>
@@ -84,10 +83,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef CONFIG_SCHED_ONEXIT
-#  error "on_exit() API must be enabled for deallocating Wi-Fi resources"
-#endif
-
 #define PHY_RF_MASK   ((1 << PHY_BT_MODULE) | (1 << PHY_WIFI_MODULE))
 
 #ifdef CONFIG_ESP32C3_WIFI_SAVE_PARAM
@@ -844,7 +839,7 @@ static int esp_int_adpt_cb(int irq, void *context, void *arg)
  *
  ****************************************************************************/
 
-static void esp_thread_semphr_free(int status, void *semphr)
+static void esp_thread_semphr_free(void *semphr)
 {
   if (semphr)
     {
@@ -1339,20 +1334,22 @@ static int IRAM_ATTR wifi_is_in_isr(void)
 static void *esp_thread_semphr_get(void)
 {
   int ret;
-  int i;
   void *sem;
-  struct tcb_s *tcb = this_task();
-  struct task_group_s *group = tcb->group;
 
-  for (i = 0; i < CONFIG_SCHED_EXIT_MAX; i++)
-    {
-      if (group->tg_exit[i].func.on == esp_thread_semphr_free)
-        {
-          break;
-        }
-    }
+  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 (i >= CONFIG_SCHED_EXIT_MAX)
+    g_wifi_tkey_init = true;
+  }
+
+  sem = pthread_getspecific(g_wifi_thread_key);
+  if (!sem)
     {
       sem = esp_semphr_create(1, 0);
       if (!sem)
@@ -1361,18 +1358,14 @@ static void *esp_thread_semphr_get(void)
           return NULL;
         }
 
-      ret = on_exit(esp_thread_semphr_free, sem);
-      if (ret < 0)
+      ret = pthread_setspecific(g_wifi_thread_key, sem);
+      if (ret)
         {
-          wlerr("ERROR: Failed to bind semaphore\n");
+          wlerr("ERROR: Failed to set specific\n");
           esp_semphr_delete(sem);
           return NULL;
         }
     }
-  else
-    {
-      sem = group->tg_exit[i].arg;
-    }
 
   return sem;
 }
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig
index 0adab7cb2d..ac1a7b1ccd 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/autopm/defconfig
@@ -52,7 +52,6 @@ CONFIG_PREALLOC_TIMERS=4
 CONFIG_PTHREAD_MUTEX_TYPES=y
 CONFIG_RAW_BINARY=y
 CONFIG_SCHED_LPWORK=y
-CONFIG_SCHED_ONEXIT=y
 CONFIG_SCHED_WAITPID=y
 CONFIG_SIG_DEFAULT=y
 CONFIG_START_DAY=6
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 46625ecc36..0ce646eb70 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/sta_softap/defconfig
@@ -65,7 +65,6 @@ CONFIG_PTHREAD_MUTEX_TYPES=y
 CONFIG_RAW_BINARY=y
 CONFIG_RR_INTERVAL=200
 CONFIG_SCHED_LPWORK=y
-CONFIG_SCHED_ONEXIT=y
 CONFIG_SCHED_WAITPID=y
 CONFIG_SIG_DEFAULT=y
 CONFIG_SPIFFS_NAME_MAX=48
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig
index ea4b5d6ece..887b0577a7 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/wapi/defconfig
@@ -50,7 +50,6 @@ CONFIG_PTHREAD_MUTEX_TYPES=y
 CONFIG_RAW_BINARY=y
 CONFIG_RR_INTERVAL=200
 CONFIG_SCHED_LPWORK=y
-CONFIG_SCHED_ONEXIT=y
 CONFIG_SCHED_WAITPID=y
 CONFIG_SIG_DEFAULT=y
 CONFIG_START_DAY=6


[incubator-nuttx] 02/03: risc-v/esp32c3: Fix leak of semaphores created by Wi-Fi kernel thread

Posted by ma...@apache.org.
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 <gu...@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 <gu...@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