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 c8713a1b480e33529de27c33312b169c7aed7a0a
Author: zhanghongyu <[email protected]>
AuthorDate: Fri Aug 22 12:03:02 2025 +0800

    net: protect the older network cards driver's tx and rx process
    
    Add netdev_lock in xxx_input and txavail to adapt to drivers that do not
    use upperhalf.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 net/can/can_input.c    | 4 ++++
 net/devif/devif_poll.c | 6 +++++-
 net/devif/ipv4_input.c | 7 ++++++-
 net/devif/ipv6_input.c | 7 ++++++-
 net/pkt/pkt_input.c    | 7 ++++++-
 5 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/net/can/can_input.c b/net/can/can_input.c
index d73a958ccc1..40f8a36cf37 100644
--- a/net/can/can_input.c
+++ b/net/can/can_input.c
@@ -33,6 +33,7 @@
 #include <nuttx/net/netdev.h>
 #include <nuttx/net/can.h>
 #include <nuttx/net/netstats.h>
+#include <nuttx/net/net.h>
 
 #include "devif/devif.h"
 #include "utils/utils.h"
@@ -289,6 +290,7 @@ int can_input(FAR struct net_driver_s *dev)
 #ifdef CONFIG_NET_STATISTICS
   g_netstats.can.recv++;
 #endif
+  netdev_lock(dev);
 
   if (dev->d_iob != NULL)
     {
@@ -301,6 +303,7 @@ int can_input(FAR struct net_driver_s *dev)
 
       dev->d_buf = buf;
 
+      netdev_unlock(dev);
       return ret;
     }
 
@@ -312,6 +315,7 @@ int can_input(FAR struct net_driver_s *dev)
 #endif
     }
 
+  netdev_unlock(dev);
   return ret;
 }
 
diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c
index 64a335c1f3c..0f4a09b1660 100644
--- a/net/devif/devif_poll.c
+++ b/net/devif/devif_poll.c
@@ -1045,9 +1045,12 @@ int devif_poll(FAR struct net_driver_s *dev, 
devif_poll_callback_t callback)
   FAR uint8_t *buf;
   int bstop;
 
+  netdev_lock(dev);
   if (dev->d_buf == NULL)
     {
-      return devif_iob_poll(dev, callback);
+      bstop = devif_iob_poll(dev, callback);
+      netdev_unlock(dev);
+      return bstop;
     }
 
   buf = dev->d_buf;
@@ -1102,6 +1105,7 @@ int devif_poll(FAR struct net_driver_s *dev, 
devif_poll_callback_t callback)
   /* Restore the flat buffer */
 
   dev->d_buf = buf;
+  netdev_unlock(dev);
 
   return bstop;
 }
diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c
index 2cf2440169d..77ee5823adc 100644
--- a/net/devif/ipv4_input.c
+++ b/net/devif/ipv4_input.c
@@ -503,6 +503,8 @@ int ipv4_input(FAR struct net_driver_s *dev)
   FAR uint8_t *buf;
   int ret;
 
+  netdev_lock(dev);
+
   /* Store reception timestamp if enabled and not provided by hardware. */
 
 #if defined(CONFIG_NET_TIMESTAMP) && 
!defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP)
@@ -520,10 +522,13 @@ int ipv4_input(FAR struct net_driver_s *dev)
 
       dev->d_buf = buf;
 
+      netdev_unlock(dev);
       return ret;
     }
 
-  return netdev_input(dev, ipv4_in, true);
+  ret = netdev_input(dev, ipv4_in, true);
+  netdev_unlock(dev);
+  return ret;
 }
 
 #endif /* CONFIG_NET_IPv4 */
diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c
index 34902f3fa8c..66fa79f6b2e 100644
--- a/net/devif/ipv6_input.c
+++ b/net/devif/ipv6_input.c
@@ -675,6 +675,8 @@ int ipv6_input(FAR struct net_driver_s *dev)
   FAR uint8_t *buf;
   int ret;
 
+  netdev_lock(dev);
+
   /* Store reception timestamp if enabled and not provided by hardware. */
 
 #if defined(CONFIG_NET_TIMESTAMP) && 
!defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP)
@@ -692,9 +694,12 @@ int ipv6_input(FAR struct net_driver_s *dev)
 
       dev->d_buf = buf;
 
+      netdev_unlock(dev);
       return ret;
     }
 
-  return netdev_input(dev, ipv6_in, true);
+  ret = netdev_input(dev, ipv6_in, true);
+  netdev_unlock(dev);
+  return ret;
 }
 #endif /* CONFIG_NET_IPv6 */
diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c
index 320eef7dc99..58a06380f35 100644
--- a/net/pkt/pkt_input.c
+++ b/net/pkt/pkt_input.c
@@ -247,6 +247,8 @@ int pkt_input(FAR struct net_driver_s *dev)
   FAR uint8_t *buf;
   int ret;
 
+  netdev_lock(dev);
+
   if (dev->d_iob != NULL)
     {
       buf = dev->d_buf;
@@ -258,10 +260,13 @@ int pkt_input(FAR struct net_driver_s *dev)
 
       dev->d_buf = buf;
 
+      netdev_unlock(dev);
       return ret;
     }
 
-  return netdev_input(dev, pkt_in, false);
+  ret = netdev_input(dev, pkt_in, false);
+  netdev_unlock(dev);
+  return ret;
 }
 
 #endif /* CONFIG_NET && CONFIG_NET_PKT */

Reply via email to