Skip to contentSkip to conversation

net: core: Assert the size of netdev_featres_t

PATCH Applied Florian Fainelli 3 participants 3 messages Apr 27, 2018 – Apr 30, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: core: Assert the size of netdev_featres_t

We have about 53 netdev_features_t bits defined and counting, add a build time check to catch when an u64 type will not be enough and we will have to convert that to a bitmap. This is done in register_netdevice() for convenience.

---
 include/linux/netdevice.h | 6 ++++++
 net/core/dev.c            | 1 +
 2 files changed, 7 insertions(+)
include/linux/netdevice.h +6 -0
index 366c32891158..4326bc6b27d1 100644
@@ -4121,6 +4121,12 @@ const char *netdev_drivername(const struct net_device *dev);
 
 void linkwatch_run_queue(void);
 
+static inline void netdev_features_size_check(void)
+{
+	BUILD_BUG_ON(sizeof(netdev_features_t) * BITS_PER_BYTE <
+		     NETDEV_FEATURE_COUNT);
+}
+
 static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
 							  netdev_features_t f2)
 {
net/core/dev.c +1 -0
index 0a2d46424069..23e6c1aa78c6 100644
@@ -7881,6 +7881,7 @@ int register_netdevice(struct net_device *dev)
 	int ret;
 	struct net *net = dev_net(dev);
 
+	netdev_features_size_check();
 	BUG_ON(dev_boot_phase);
 	ASSERT_RTNL();
 
Signature · 1 line
2.14.1
maintainer Applied
#1 lore raw

From: Florian Fainelli <[email protected]>
Date: Fri, 27 Apr 2018 13:11:14 -0700

Quoted 6 lines

We have about 53 netdev_features_t bits defined and counting, add a build time check to catch when an u64 type will not be enough and we will have to convert that to a bitmap. This is done in register_netdevice() for convenience.

Applied, but I don't know about putting that check as an inline function in a header file included by every networking foo.c file.

It means that the inline function has to be parsed and (potentially) optimized by the compiler for every foo.c file that either directly or indirectly includes that header.

#2 lore raw
In reply to Florian Fainelli
Quoted 33 lines · On Fri, 27 Apr 2018 13:11:14 -0700 Florian Fainelli <[email protected]>…

We have about 53 netdev_features_t bits defined and counting, add a build time check to catch when an u64 type will not be enough and we will have to convert that to a bitmap. This is done in register_netdevice() for convenience.

---
 include/linux/netdevice.h | 6 ++++++
 net/core/dev.c            | 1 +
 2 files changed, 7 insertions(+)
include/linux/netdevice.h +6 -0
index 366c32891158..4326bc6b27d1 100644
@@ -4121,6 +4121,12 @@ const char *netdev_drivername(const struct net_device *dev);
 
 void linkwatch_run_queue(void);
 
+static inline void netdev_features_size_check(void)
+{
+	BUILD_BUG_ON(sizeof(netdev_features_t) * BITS_PER_BYTE <
+		     NETDEV_FEATURE_COUNT);
+}
+
 static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
 							  netdev_features_t f2)
 {
net/core/dev.c +0 -0
index 0a2d46424069..23e6c1aa78c6 100644

net/core/dev.c int register_netdevice(struct net_device *dev) · line 7887

Quoted 7 lines
net/core/dev.c +1 -0
@@ -7881,6 +7881,7 @@ int register_netdevice(struct net_device *dev)
 	int ret;
 	struct net *net = dev_net(dev);
 
+	netdev_features_size_check();
 	BUG_ON(dev_boot_phase);
 	ASSERT_RTNL();
 

You don't have do this kind of inline function stuff to get the check. Why not just put BUILD_BUG_ON directly in net/core/dev.c Could be anywhere. Rather than adding inline in the header file.