[PATCH net mlxsw 2/2] mlxsw: spectrum_switchdev: Fix port_vlan refcounting

Petr Machata petrm at mellanox.com
Fri Jun 8 01:01:23 AEST 2018

Switchdev notifications for addition of SWITCHDEV_OBJ_ID_PORT_VLAN are
distributed not only on clean addition, but also when flags on an
existing VLAN are changed. Thus it is wrong to look up the corresponding
port_vlan object by calling mlxsw_sp_port_vlan_get(), which bumps
reference of a preexisting port_vlan. This leads to reference counting
discrepancy, which triggers a warning in mlxsw_sp_port_remove on mlxsw

Fix by replacing the problematic call with a combination of calls to
mlxsw_sp_port_vlan_find_by_vid() and mlxsw_sp_port_vlan_create().

Fixes: c57529e1d5d8 ("mlxsw: spectrum: Replace vPorts with Port-VLAN")
Signed-off-by: Petr Machata <petrm at mellanox.com>
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index e97652c..e9204a1 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1105,7 +1105,10 @@ mlxsw_sp_bridge_port_vlan_add(struct mlxsw_sp_port *mlxsw_sp_port,
 	u16 old_pvid = mlxsw_sp_port->pvid;
 	int err;
-	mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_get(mlxsw_sp_port, vid);
+	mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
+	if (!mlxsw_sp_port_vlan)
+		mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_create(mlxsw_sp_port,
+							       vid);
 	if (IS_ERR(mlxsw_sp_port_vlan))
 		return PTR_ERR(mlxsw_sp_port_vlan);

More information about the Linux-mlxsw mailing list