Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: fix off-by-one in maximum bridge ID determination

Prior to the blamed commit, the bridge_num range was from
0 to ds->max_num_bridges - 1. After the commit, it is from
1 to ds->max_num_bridges.

So this check:
if (bridge_num >= max)
return 0;
must be updated to:
if (bridge_num > max)
return 0;

in order to allow the last bridge_num value (==max) to be used.

This is easiest visible when a driver sets ds->max_num_bridges=1.
The observed behaviour is that even the first created bridge triggers
the netlink extack "Range of offloadable bridges exceeded" warning, and
is handled in software rather than being offloaded.

Fixes: 3f9bb0301d50 ("net: dsa: make dp->bridge_num one-based")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20260120211039.3228999-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
dfca045c bbb11b8d

+1 -1
+1 -1
net/dsa/dsa.c
··· 158 158 bridge_num = find_next_zero_bit(&dsa_fwd_offloading_bridges, 159 159 DSA_MAX_NUM_OFFLOADING_BRIDGES, 160 160 1); 161 - if (bridge_num >= max) 161 + if (bridge_num > max) 162 162 return 0; 163 163 164 164 set_bit(bridge_num, &dsa_fwd_offloading_bridges);