]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: dsa: add bridge member iteration macro
authorDaniel Golle <daniel@makrotopia.org>
Wed, 1 Apr 2026 13:34:42 +0000 (14:34 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Apr 2026 01:30:33 +0000 (18:30 -0700)
Drivers that offload bridges need to iterate over the ports that are
members of a given bridge, for example to rebuild per-port forwarding
bitmaps when membership changes. Currently drivers typically open-code
this by combining dsa_switch_for_each_user_port() with a
dsa_port_offloads_bridge_dev() check, or cache bridge membership
within the driver.

Add dsa_switch_for_each_bridge_member() macro to express this pattern
directly, and use it for the existing dsa_bridge_ports() inline
helper.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Link: https://patch.msgid.link/e7136aaa26773f39e805a00fe4ecf13cd2b83fc0.1775049897.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/dsa.h

index e93b4feaca96667e004b6bb2081424362c490f28..8b6d34e8a6f0d3a229c9150ee6b8e28fd3560f91 100644 (file)
@@ -831,15 +831,18 @@ dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
        return false;
 }
 
+#define dsa_switch_for_each_bridge_member(_dp, _ds, _bdev) \
+       dsa_switch_for_each_user_port(_dp, _ds) \
+               if (dsa_port_offloads_bridge_dev(_dp, _bdev))
+
 static inline u32
 dsa_bridge_ports(struct dsa_switch *ds, const struct net_device *bdev)
 {
        struct dsa_port *dp;
        u32 mask = 0;
 
-       dsa_switch_for_each_user_port(dp, ds)
-               if (dsa_port_offloads_bridge_dev(dp, bdev))
-                       mask |= BIT(dp->index);
+       dsa_switch_for_each_bridge_member(dp, ds, bdev)
+               mask |= BIT(dp->index);
 
        return mask;
 }