diff options
| author | Nicolai Buchwitz <nb@tipi-net.de> | 2026-10-02 11:42:07 +0200 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-10-05 17:05:36 -0700 |
| commit | 57f66330c6bb264dd558ff7abc06dccf8191a37a (patch) | |
| tree | 24fb1c591406fd2f2e8f8d0e94a67fbc3d06b4b1 /net | |
| parent | a032c035272aff415a3ac7ec48bd16aada5fc4bf (diff) | |
| download | linux-next-57f66330c6bb264dd558ff7abc06dccf8191a37a.tar.gz linux-next-57f66330c6bb264dd558ff7abc06dccf8191a37a.zip | |
net: move the netdev_ops checks into a helper
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@tipi-net.de>
Link: https://patch.msgid.link/20261002094211.2350702-2-nb@tipi-net.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net')
| -rw-r--r-- | net/core/dev.c | 32 |
1 files 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) |
