Skip to content

Commit fa8fd31

Browse files
Henry Martinkuba-moo
authored andcommitted
net/mlx5: Move ttc allocation after switch case to prevent leaks
Relocate the memory allocation for ttc table after the switch statement that validates params->ns_type in both mlx5_create_inner_ttc_table() and mlx5_create_ttc_table(). This ensures memory is only allocated after confirming valid input, eliminating potential memory leaks when invalid ns_type cases occur. Fixes: 137f3d5 ("net/mlx5: Support matching on l4_type for ttc_table") Signed-off-by: Henry Martin <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9103703 commit fa8fd31

File tree

1 file changed

+8
-8
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/lib

1 file changed

+8
-8
lines changed

drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,6 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
637637
bool use_l4_type;
638638
int err;
639639

640-
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
641-
if (!ttc)
642-
return ERR_PTR(-ENOMEM);
643-
644640
switch (params->ns_type) {
645641
case MLX5_FLOW_NAMESPACE_PORT_SEL:
646642
use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
@@ -654,6 +650,10 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev,
654650
return ERR_PTR(-EINVAL);
655651
}
656652

653+
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
654+
if (!ttc)
655+
return ERR_PTR(-ENOMEM);
656+
657657
ns = mlx5_get_flow_namespace(dev, params->ns_type);
658658
if (!ns) {
659659
kvfree(ttc);
@@ -715,10 +715,6 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
715715
bool use_l4_type;
716716
int err;
717717

718-
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
719-
if (!ttc)
720-
return ERR_PTR(-ENOMEM);
721-
722718
switch (params->ns_type) {
723719
case MLX5_FLOW_NAMESPACE_PORT_SEL:
724720
use_l4_type = MLX5_CAP_GEN_2(dev, pcc_ifa2) &&
@@ -732,6 +728,10 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev,
732728
return ERR_PTR(-EINVAL);
733729
}
734730

731+
ttc = kvzalloc(sizeof(*ttc), GFP_KERNEL);
732+
if (!ttc)
733+
return ERR_PTR(-ENOMEM);
734+
735735
ns = mlx5_get_flow_namespace(dev, params->ns_type);
736736
if (!ns) {
737737
kvfree(ttc);

0 commit comments

Comments
 (0)