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 2ebb08e78f67f5d80e13c62ece91359bcb769f66
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Jul 2 11:44:15 2025 +0800

    netdev_upperhalf: avoid recursion during transmission
    
    to avoid uncontrollable stack overhead, we actively
    avoid scenarios where recursion occurs.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 drivers/net/netdev_upperhalf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index 3d26879c46a..bf67623fbfd 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -86,6 +86,8 @@ struct netdev_upperhalf_s
   struct netdev_vlan_entry_s vlan[CONFIG_NET_VLAN_COUNT];
 #endif
 
+  bool txing;
+
   /* Deferring process to work queue or thread */
 
   union
@@ -381,11 +383,13 @@ static void netdev_upper_txavail_work(FAR struct 
netdev_upperhalf_s *upper)
   /* Ignore the notification if the interface is not yet up */
 
   net_lock();
-  if (IFF_IS_UP(dev->d_flags))
+  if (IFF_IS_UP(dev->d_flags) && !upper->txing)
     {
       DEBUGASSERT(dev->d_buf == NULL); /* Make sure: IOB only. */
+      upper->txing = true;
       while (netdev_upper_can_tx(upper) &&
              netdev_upper_tx(dev) == NETDEV_TX_CONTINUE);
+      upper->txing = false;
     }
 
   net_unlock();
@@ -1408,6 +1412,8 @@ int netdev_lower_register(FAR struct netdev_lowerhalf_s 
*dev,
       return -ENOMEM;
     }
 
+  upper->txing = false;
+
   dev->netdev.d_ifup    = netdev_upper_ifup;
   dev->netdev.d_ifdown  = netdev_upper_ifdown;
   dev->netdev.d_txavail = netdev_upper_txavail;

Reply via email to