diff mbox

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

Message ID de06513da07820ca281fa153848b264f10aef70f.1528383246.git.petrm@mellanox.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Petr Machata June 7, 2018, 3:01 p.m. UTC
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
unload.

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@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox

Patch

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);