Misc vlan cleanups
Subsystems (2)
v2 cover Misc vlan cleanups
This patch series addresses compilation issues with objtool when VLAN support is disabled (CONFIG_VLAN_8021Q=n) and makes related improvements to the VLAN infrastructure.
When CONFIG_VLAN_8021Q=n, CONFIG_OBJTOOL=y, and CONFIG_OBJTOOL_WERROR=y, the following compilation error occurs:
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.o: error: objtool: parse_mirred.isra.0+0x370: mlx5e_tc_act_vlan_add_push_action() missing __noreturn in .c/.h or NORETURN() in noreturns.h
The error occurs because objtool cannot determine that unreachable BUG() calls in VLAN code paths are actually dead code when VLAN support is disabled.
First patch makes is_vlan_dev() a stub when VLAN is not configured, allows compile-out of VLAN-dependent dead code paths and resolves the objtool compilation error.
Second patch replaces BUG() calls with WARN_ON_ONCE(), as the usage of BUG() should be avoided.
Third patch uses the "kernel" way of testing whether an option is configured as builtin/module, instead of open-coding it.
Changelog -v1->v2: https://lore.kernel.org/netdev/[email protected]/
* Add the first patch, alternative approach suggested by Jakub
Gal Pressman (3):
net: vlan: Make is_vlan_dev() a stub when VLAN is not configured
net: vlan: Replace BUG() with WARN_ON_ONCE() in vlan_dev_* stubs
net: vlan: Use IS_ENABLED() helper for CONFIG_VLAN_8021Q guard
include/linux/if_vlan.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/3 net: vlan: Make is_vlan_dev() a stub when VLAN is not configured
Add a stub implementation of is_vlan_dev() that returns false when VLAN support is not compiled in (CONFIG_VLAN_8021Q=n).
This allows us to compile-out VLAN-dependent dead code when it is not needed.
This also resolves the following compilation error when:
* CONFIG_VLAN_8021Q=n
* CONFIG_OBJTOOL=y
* CONFIG_OBJTOOL_WERROR=y
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.o: error: objtool: parse_mirred.isra.0+0x370: mlx5e_tc_act_vlan_add_push_action() missing __noreturn in .c/.h or NORETURN() in noreturns.h
The error occurs because objtool cannot determine that unreachable BUG() (which doesn't return) calls in VLAN code paths are actually dead code when VLAN support is disabled.
--- include/linux/if_vlan.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
include/linux/if_vlan.h +10 -5
@@ -79,11 +79,6 @@ static inline struct vlan_ethhdr *skb_vlan_eth_hdr(const struct sk_buff *skb)/* found in socket.c */ extern void vlan_ioctl_set (int (*hook)(struct net *,void __user *)); -static inline bool is_vlan_dev (const struct net_device *dev) -{ -return dev->priv_flags &IFF_802_1Q_VLAN ; -} -#define skb_vlan_tag_present (__skb) (!!(__skb)->vlan_all)#define skb_vlan_tag_get (__skb) ((__skb)->vlan_tci)#define skb_vlan_tag_get_id (__skb) ((__skb)->vlan_tci & VLAN_VID_MASK)
@@ -200,6 +195,11 @@ struct vlan_dev_priv {#endif }; +static inline bool is_vlan_dev (const struct net_device *dev) +{ +return dev->priv_flags &IFF_802_1Q_VLAN ; +} +static inline struct vlan_dev_priv *vlan_dev_priv (const struct net_device *dev) {return netdev_priv (dev);
@@ -237,6 +237,11 @@ extern void vlan_vids_del_by_dev(struct net_device *dev,extern bool vlan_uses_dev (const struct net_device *dev);#else +static inline bool is_vlan_dev (const struct net_device *dev) +{ +return false; +} +static inline struct net_device *__vlan_find_dev_deep_rcu (struct net_device *real_dev,__be16 vlan_proto,u16 vlan_id)
Signature · 1 line
2.40.1
PATCH v2 2/3 net: vlan: Replace BUG() with WARN_ON_ONCE() in vlan_dev_* stubs
In reply to Gal PressmanWhen CONFIG_VLAN_8021Q=n, a set of stub helpers are used, three of these helpers use BUG() unconditionally.
This code should not be reached, as callers of these functions should always check for is_vlan_dev() first, but the usage of BUG() is not recommended, replace it with WARN_ON() instead.
--- include/linux/if_vlan.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/if_vlan.h +3 -3
@@ -259,19 +259,19 @@ vlan_for_each(struct net_device *dev,static inline struct net_device *vlan_dev_real_dev (const struct net_device *dev) { -BUG (); +WARN_ON_ONCE (1 );return NULL ; }static inline u16 vlan_dev_vlan_id (const struct net_device *dev) { -BUG (); +WARN_ON_ONCE (1 );return 0 ; }static inline __be16 vlan_dev_vlan_proto (const struct net_device *dev) { -BUG (); +WARN_ON_ONCE (1 );return 0 ; }
Signature · 1 line
2.40.1
PATCH v2 3/3 net: vlan: Use IS_ENABLED() helper for CONFIG_VLAN_8021Q guard
In reply to Gal PressmanThe header currently tests the VLAN core with an explicit pair of 'if defined' checks:
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
Instead, use IS_ENABLED() which is the kernel way to test whether an option is configured as builtin/module.
This is purely cosmetic – no functional changes.
--- include/linux/if_vlan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/if_vlan.h +1 -1
@@ -131,7 +131,7 @@ struct vlan_pcpu_stats {u32 tx_dropped; }; -#if defined(CONFIG_VLAN_8021Q ) || defined(CONFIG_VLAN_8021Q_MODULE ) +#if IS_ENABLED (CONFIG_VLAN_8021Q )extern struct net_device *__vlan_find_dev_deep_rcu (struct net_device *real_dev,__be16 vlan_proto,u16 vlan_id);
Signature · 1 line
2.40.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 16 Jun 2025 16:26:23 +0300 you wrote:
This patch series addresses compilation issues with objtool when VLAN support is disabled (
CONFIG_VLAN_8021Q=n) and makes related improvements to the VLAN infrastructure.When
CONFIG_VLAN_8021Q=n,CONFIG_OBJTOOL=y, andCONFIG_OBJTOOL_WERROR=y, the following compilation error occurs:[...]
Here is the summary with links:
- [net-next,v2,1/3] net: vlan: Make is_vlan_dev() a stub when VLAN is not configured
https://git.kernel.org/netdev/net-next/c/2de1ba0887e5 - [net-next,v2,2/3] net: vlan: Replace BUG() with WARN_ON_ONCE() in vlan_dev_* stubs https://git.kernel.org/netdev/net-next/c/60a8b1a5d082 - [net-next,v2,3/3] net: vlan: Use IS_ENABLED() helper for CONFIG_VLAN_8021Q guard https://git.kernel.org/netdev/net-next/c/9c5f5a5bf0da
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html