diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2021-12-06 19:57:47 +0300 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2021-12-09 01:31:14 +0300 |
commit | 3f9bb0301d50ce27421eff4b710c2bbe58111a83 (patch) | |
tree | 91271bc43b14b643d9b82b08df871ee3d2e8da22 /drivers/net/dsa | |
parent | 1fe5b01262844be03de98afdd56d1d393df04d7e (diff) | |
download | linux-3f9bb0301d50ce27421eff4b710c2bbe58111a83.tar.xz |
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 'drivers/net/dsa')
-rw-r--r-- | drivers/net/dsa/mv88e6xxx/chip.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index f00cbf5753b9..de3401b2c86c 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1250,10 +1250,10 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) /* dev is a virtual bridge */ } else { list_for_each_entry(dp, &dst->ports, list) { - if (dp->bridge_num < 0) + if (!dp->bridge_num) continue; - if (dp->bridge_num + 1 + dst->last_switch != dev) + if (dp->bridge_num + dst->last_switch != dev) continue; br = dp->bridge_dev; @@ -2527,9 +2527,9 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, * physical switches, so start from beyond that range. */ static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds, - int bridge_num) + unsigned int bridge_num) { - u8 dev = bridge_num + ds->dst->last_switch + 1; + u8 dev = bridge_num + ds->dst->last_switch; struct mv88e6xxx_chip *chip = ds->priv; int err; @@ -2542,14 +2542,14 @@ static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds, static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port, struct net_device *br, - int bridge_num) + unsigned int bridge_num) { return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num); } static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port, struct net_device *br, - int bridge_num) + unsigned int bridge_num) { int err; |