You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2024/05/14 20:43:32 UTC
(nuttx) branch master updated: net/netdev: Check quota when registering lower-half devices
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c234fac910 net/netdev: Check quota when registering lower-half devices
c234fac910 is described below
commit c234fac91010e2c1b872eb58d77cbddf27b38d6a
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Mon May 13 17:18:58 2024 +0800
net/netdev: Check quota when registering lower-half devices
Some drivers may set too big quota by accident and consume all of our
buffers, so we add a check when registering devices.
Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
drivers/net/netdev_upperhalf.c | 36 +++++++++++++++++++++++++++++++++++-
include/nuttx/net/netdev_lowerhalf.h | 1 +
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index a1f3997010..a97f3202b3 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -115,6 +115,40 @@ static int quota_fetch_dec(FAR struct netdev_lowerhalf_s *lower,
#endif
}
+/****************************************************************************
+ * Name: quota_is_valid
+ *
+ * Description:
+ * Check if the quota of the lower half is not too big.
+ *
+ ****************************************************************************/
+
+static bool quota_is_valid(FAR struct netdev_lowerhalf_s *lower)
+{
+ int total = 0;
+ int type;
+
+ for (type = 0; type < NETPKT_TYPENUM; type++)
+ {
+ total += netdev_lower_quota_load(lower, type);
+ }
+
+ if (total > NETPKT_BUFNUM)
+ {
+ nerr("ERROR: Too big quota when registering device: %d\n", total);
+ return false;
+ }
+
+ if (total > NETPKT_BUFNUM / 2)
+ {
+ nwarn("WARNING: The quota of the registering device may consume more "
+ "than half of the network buffers, which may hurt performance. "
+ "Please consider decreasing driver quota or increasing nIOB.\n");
+ }
+
+ return true;
+}
+
/****************************************************************************
* Name: netpkt_get
*
@@ -1029,7 +1063,7 @@ int netdev_lower_register(FAR struct netdev_lowerhalf_s *dev,
FAR struct netdev_upperhalf_s *upper;
int ret;
- if (dev == NULL || dev->ops == NULL ||
+ if (dev == NULL || quota_is_valid(dev) == false || dev->ops == NULL ||
dev->ops->transmit == NULL || dev->ops->receive == NULL)
{
return -EINVAL;
diff --git a/include/nuttx/net/netdev_lowerhalf.h b/include/nuttx/net/netdev_lowerhalf.h
index 009d47f23e..bfe4089225 100644
--- a/include/nuttx/net/netdev_lowerhalf.h
+++ b/include/nuttx/net/netdev_lowerhalf.h
@@ -69,6 +69,7 @@
*/
#define NETPKT_BUFLEN CONFIG_IOB_BUFSIZE
+#define NETPKT_BUFNUM CONFIG_IOB_NBUFFERS
/****************************************************************************
* Public Types