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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3778834527ad2548c2d6764522774ce6fe939a7b
Author: zhanghongyu <[email protected]>
AuthorDate: Fri Nov 7 15:13:46 2025 +0800

    netdev_foreach.c: add lock protection during the traversal process
    
    when traversing g_netdevices, it is necessary to ensure that they are
    not modified during the traversal.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 net/netdev/netdev_foreach.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/netdev/netdev_foreach.c b/net/netdev/netdev_foreach.c
index 230d2859abf..537167c88b6 100644
--- a/net/netdev/netdev_foreach.c
+++ b/net/netdev/netdev_foreach.c
@@ -71,6 +71,7 @@ int netdev_foreach(netdev_callback_t callback, FAR void *arg)
 
   if (callback != NULL)
     {
+      netdev_list_lock();
       for (dev = g_netdevices; dev; dev = dev->flink)
         {
           if (callback(dev, arg) != 0)
@@ -79,6 +80,8 @@ int netdev_foreach(netdev_callback_t callback, FAR void *arg)
               break;
             }
         }
+
+      netdev_list_unlock();
     }
 
   return ret;

Reply via email to