aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdo Schimmel <idosch@mellanox.com>2018-01-18 09:42:10 -0500
committerDavid S. Miller <davem@davemloft.net>2018-01-18 20:54:58 -0500
commited604c5da34d96ae289c67c46dedd7dfd9fa795e (patch)
tree858fc00d3d83135c84ae254d88fab682c8809455
parentd0c081b49137cd3200f2023c0875723be66e7ce5 (diff)
mlxsw: spectrum_router: Free LPM tree upon failure
When a new LPM tree is created, we try to replace the trees in the existing virtual routers with it. If we fail, the tree needs to be freed. Currently, this does not happen in the unlikely case where we fail to bind the tree to the first virtual router, since its reference count never transitions from 1 to 0. Fix that by taking a reference before binding the tree. Fixes: fc922bb0dd94 ("mlxsw: spectrum_router: Use one LPM tree for all virtual routers") Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 434b3922b34f..6c0391c13fe0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -821,13 +821,18 @@ static int mlxsw_sp_vr_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp,
821 struct mlxsw_sp_lpm_tree *old_tree = fib->lpm_tree; 821 struct mlxsw_sp_lpm_tree *old_tree = fib->lpm_tree;
822 int err; 822 int err;
823 823
824 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, new_tree->id);
825 if (err)
826 return err;
827 fib->lpm_tree = new_tree; 824 fib->lpm_tree = new_tree;
828 mlxsw_sp_lpm_tree_hold(new_tree); 825 mlxsw_sp_lpm_tree_hold(new_tree);
826 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, new_tree->id);
827 if (err)
828 goto err_tree_bind;
829 mlxsw_sp_lpm_tree_put(mlxsw_sp, old_tree); 829 mlxsw_sp_lpm_tree_put(mlxsw_sp, old_tree);
830 return 0; 830 return 0;
831
832err_tree_bind:
833 mlxsw_sp_lpm_tree_put(mlxsw_sp, new_tree);
834 fib->lpm_tree = old_tree;
835 return err;
831} 836}
832 837
833static int mlxsw_sp_vrs_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp, 838static int mlxsw_sp_vrs_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp,
@@ -868,11 +873,14 @@ err_tree_replace:
868 return err; 873 return err;
869 874
870no_replace: 875no_replace:
871 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, new_tree->id);
872 if (err)
873 return err;
874 fib->lpm_tree = new_tree; 876 fib->lpm_tree = new_tree;
875 mlxsw_sp_lpm_tree_hold(new_tree); 877 mlxsw_sp_lpm_tree_hold(new_tree);
878 err = mlxsw_sp_vr_lpm_tree_bind(mlxsw_sp, fib, new_tree->id);
879 if (err) {
880 mlxsw_sp_lpm_tree_put(mlxsw_sp, new_tree);
881 fib->lpm_tree = NULL;
882 return err;
883 }
876 return 0; 884 return 0;
877} 885}
878 886