diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2021-12-06 18:57:47 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2021-12-08 14:31:14 -0800 |
commit | 3f9bb0301d50ce27421eff4b710c2bbe58111a83 (patch) | |
tree | 91271bc43b14b643d9b82b08df871ee3d2e8da22 /net/dsa/port.c | |
parent | 1fe5b01262844be03de98afdd56d1d393df04d7e (diff) |
net: dsa: make dp->bridge_num one-based
I have seen too many bugs already due to the fact that we must encode an
invalid dp->bridge_num as a negative value, because the natural tendency
is to check that invalid value using (!dp->bridge_num). Latest example
can be seen in commit 1bec0f05062c ("net: dsa: fix bridge_num not
getting cleared after ports leaving the bridge").
Convert the existing users to assume that dp->bridge_num == 0 is the
encoding for invalid, and valid bridge numbers start from 1.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/dsa/port.c')
-rw-r--r-- | net/dsa/port.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/net/dsa/port.c b/net/dsa/port.c index 6d5ebe61280b..9a77bd1373e2 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -273,14 +273,14 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp) static void dsa_port_bridge_tx_fwd_unoffload(struct dsa_port *dp, struct net_device *bridge_dev) { - int bridge_num = dp->bridge_num; + unsigned int bridge_num = dp->bridge_num; struct dsa_switch *ds = dp->ds; /* No bridge TX forwarding offload => do nothing */ - if (!ds->ops->port_bridge_tx_fwd_unoffload || dp->bridge_num == -1) + if (!ds->ops->port_bridge_tx_fwd_unoffload || !dp->bridge_num) return; - dp->bridge_num = -1; + dp->bridge_num = 0; dsa_bridge_num_put(bridge_dev, bridge_num); @@ -295,14 +295,15 @@ static bool dsa_port_bridge_tx_fwd_offload(struct dsa_port *dp, struct net_device *bridge_dev) { struct dsa_switch *ds = dp->ds; - int bridge_num, err; + unsigned int bridge_num; + int err; if (!ds->ops->port_bridge_tx_fwd_offload) return false; bridge_num = dsa_bridge_num_get(bridge_dev, ds->num_fwd_offloading_bridges); - if (bridge_num < 0) + if (!bridge_num) return false; dp->bridge_num = bridge_num; |