Skip to content

Commit 571c569

Browse files
pmachataPaolo Abeni
authored andcommitted
mlxsw: spectrum_router: Extract a helper to free a RIF
Right now freeing the object that mlxsw uses to keep track of a RIF is as simple as calling a kfree. But later on as CRIF abstraction is brought in, it will involve severing the link between CRIF and its RIF as well. Better to have the logic encapsulated in a helper. Since a helper is being introduced, make it a full-fledged destructor and have it validate that the objects tracked at the RIF have been released. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Amit Cohen <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 532b6e2 commit 571c569

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7903,6 +7903,13 @@ static struct mlxsw_sp_rif *mlxsw_sp_rif_alloc(size_t rif_size, u16 rif_index,
79037903
return rif;
79047904
}
79057905

7906+
static void mlxsw_sp_rif_free(struct mlxsw_sp_rif *rif)
7907+
{
7908+
WARN_ON(!list_empty(&rif->neigh_list));
7909+
WARN_ON(!list_empty(&rif->nexthop_list));
7910+
kfree(rif);
7911+
}
7912+
79067913
struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
79077914
u16 rif_index)
79087915
{
@@ -8209,7 +8216,7 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp,
82098216
err_fid_get:
82108217
mlxsw_sp->router->rifs[rif_index] = NULL;
82118218
dev_put(params->dev);
8212-
kfree(rif);
8219+
mlxsw_sp_rif_free(rif);
82138220
err_rif_alloc:
82148221
mlxsw_sp_rif_index_free(mlxsw_sp, rif_index, rif_entries);
82158222
err_rif_index_alloc:
@@ -8249,7 +8256,7 @@ static void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif)
82498256
mlxsw_sp_fid_put(fid);
82508257
mlxsw_sp->router->rifs[rif->rif_index] = NULL;
82518258
dev_put(dev);
8252-
kfree(rif);
8259+
mlxsw_sp_rif_free(rif);
82538260
mlxsw_sp_rif_index_free(mlxsw_sp, rif_index, rif_entries);
82548261
vr->rif_count--;
82558262
mlxsw_sp_vr_put(mlxsw_sp, vr);
@@ -9902,7 +9909,7 @@ mlxsw_sp_ul_rif_create(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_vr *vr,
99029909

99039910
ul_rif_op_err:
99049911
mlxsw_sp->router->rifs[rif_index] = NULL;
9905-
kfree(ul_rif);
9912+
mlxsw_sp_rif_free(ul_rif);
99069913
err_rif_alloc:
99079914
mlxsw_sp_rif_index_free(mlxsw_sp, rif_index, rif_entries);
99089915
return ERR_PTR(err);
@@ -9917,7 +9924,7 @@ static void mlxsw_sp_ul_rif_destroy(struct mlxsw_sp_rif *ul_rif)
99179924
atomic_sub(rif_entries, &mlxsw_sp->router->rifs_count);
99189925
mlxsw_sp_rif_ipip_lb_ul_rif_op(ul_rif, false);
99199926
mlxsw_sp->router->rifs[ul_rif->rif_index] = NULL;
9920-
kfree(ul_rif);
9927+
mlxsw_sp_rif_free(ul_rif);
99219928
mlxsw_sp_rif_index_free(mlxsw_sp, rif_index, rif_entries);
99229929
}
99239930

0 commit comments

Comments
 (0)