[PATCH net-next v2 1/3] net: move the netdev_ops checks into a helper
From: Nicolai Buchwitz
Date: Fri Oct 02 2026 - 05:48:45 EST
register_netdevice() already does two ops sanity checks and is about to
get a third. Collect them in netdev_check_ops().
The call stays after ndo_init() because drivers set features from there.
Signed-off-by: Nicolai Buchwitz <nb@xxxxxxxxxxx>
---
net/core/dev.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index 5ac08da8b9d7..a44bcfc29d54 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11451,6 +11451,24 @@ static void netdev_free_phy_link_topology(struct net_device *dev)
}
}
+static int netdev_check_ops(struct net_device *dev)
+{
+ const struct net_device_ops *ops = dev->netdev_ops;
+
+ if (((dev->hw_features | dev->features) &
+ NETIF_F_HW_VLAN_CTAG_FILTER) &&
+ (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
+ netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n");
+ return -EINVAL;
+ }
+
+ if (netdev_need_ops_lock(dev) && ops->ndo_set_rx_mode &&
+ !ops->ndo_set_rx_mode_async)
+ netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n");
+
+ return 0;
+}
+
/**
* register_netdevice() - register a network device
* @dev: device to register
@@ -11506,19 +11524,9 @@ int register_netdevice(struct net_device *dev)
}
}
- if (((dev->hw_features | dev->features) &
- NETIF_F_HW_VLAN_CTAG_FILTER) &&
- (!dev->netdev_ops->ndo_vlan_rx_add_vid ||
- !dev->netdev_ops->ndo_vlan_rx_kill_vid)) {
- netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n");
- ret = -EINVAL;
+ ret = netdev_check_ops(dev);
+ if (ret)
goto err_uninit;
- }
-
- if (netdev_need_ops_lock(dev) &&
- dev->netdev_ops->ndo_set_rx_mode &&
- !dev->netdev_ops->ndo_set_rx_mode_async)
- netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n");
ret = netdev_do_alloc_pcpu_stats(dev);
if (ret)
base-commit: 071876fd50482a68603a9460d80dd6dd58827ee1
--
2.53.0