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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-08-22 12:03:02 +08:00
committed by Xiang Xiao
parent 6b625dfdf2
commit c8713a1b48
5 changed files with 27 additions and 4 deletions
+4
View File
@@ -33,6 +33,7 @@
#include <nuttx/net/netdev.h> #include <nuttx/net/netdev.h>
#include <nuttx/net/can.h> #include <nuttx/net/can.h>
#include <nuttx/net/netstats.h> #include <nuttx/net/netstats.h>
#include <nuttx/net/net.h>
#include "devif/devif.h" #include "devif/devif.h"
#include "utils/utils.h" #include "utils/utils.h"
@@ -289,6 +290,7 @@ int can_input(FAR struct net_driver_s *dev)
#ifdef CONFIG_NET_STATISTICS #ifdef CONFIG_NET_STATISTICS
g_netstats.can.recv++; g_netstats.can.recv++;
#endif #endif
netdev_lock(dev);
if (dev->d_iob != NULL) if (dev->d_iob != NULL)
{ {
@@ -301,6 +303,7 @@ int can_input(FAR struct net_driver_s *dev)
dev->d_buf = buf; dev->d_buf = buf;
netdev_unlock(dev);
return ret; return ret;
} }
@@ -312,6 +315,7 @@ int can_input(FAR struct net_driver_s *dev)
#endif #endif
} }
netdev_unlock(dev);
return ret; return ret;
} }
+5 -1
View File
@@ -1045,9 +1045,12 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
FAR uint8_t *buf; FAR uint8_t *buf;
int bstop; int bstop;
netdev_lock(dev);
if (dev->d_buf == NULL) 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; 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 */ /* Restore the flat buffer */
dev->d_buf = buf; dev->d_buf = buf;
netdev_unlock(dev);
return bstop; return bstop;
} }
+6 -1
View File
@@ -503,6 +503,8 @@ int ipv4_input(FAR struct net_driver_s *dev)
FAR uint8_t *buf; FAR uint8_t *buf;
int ret; int ret;
netdev_lock(dev);
/* Store reception timestamp if enabled and not provided by hardware. */ /* Store reception timestamp if enabled and not provided by hardware. */
#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) #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; dev->d_buf = buf;
netdev_unlock(dev);
return ret; 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 */ #endif /* CONFIG_NET_IPv4 */
+6 -1
View File
@@ -675,6 +675,8 @@ int ipv6_input(FAR struct net_driver_s *dev)
FAR uint8_t *buf; FAR uint8_t *buf;
int ret; int ret;
netdev_lock(dev);
/* Store reception timestamp if enabled and not provided by hardware. */ /* Store reception timestamp if enabled and not provided by hardware. */
#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) #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; dev->d_buf = buf;
netdev_unlock(dev);
return ret; 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 */ #endif /* CONFIG_NET_IPv6 */
+6 -1
View File
@@ -247,6 +247,8 @@ int pkt_input(FAR struct net_driver_s *dev)
FAR uint8_t *buf; FAR uint8_t *buf;
int ret; int ret;
netdev_lock(dev);
if (dev->d_iob != NULL) if (dev->d_iob != NULL)
{ {
buf = dev->d_buf; buf = dev->d_buf;
@@ -258,10 +260,13 @@ int pkt_input(FAR struct net_driver_s *dev)
dev->d_buf = buf; dev->d_buf = buf;
netdev_unlock(dev);
return ret; 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 */ #endif /* CONFIG_NET && CONFIG_NET_PKT */