Message ID | 20250415124128.59198-3-bsdhenrymartin@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | net/mlx5: Fix NULL dereference and memory leak in ttc_table creation | expand |
On 15/04/2025 15:41, Henry Martin wrote: > Free ttc table memory when unsupported ttc_type is passed, to avoid > memory leak on the default error path in mlx5_create_inner_ttc_table() > and mlx5_create_ttc_table(). > > Fixes: 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table") > Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com> > --- > drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c > index e48afd620d7e..077fe908bf86 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c > @@ -651,6 +651,7 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, > MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, inner_l4_type); > break; > default: > + kvfree(ttc); > return ERR_PTR(-EINVAL); > } > > @@ -729,6 +730,7 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, > MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, outer_l4_type); > break; > default: > + kvfree(ttc); > return ERR_PTR(-EINVAL); > } > What about just moving the ttc allocation after the switch case? Mark
> What about just moving the ttc allocation after the switch case?
Thanks for the suggestion. Moving the allocation after the switch statement is
indeed a cleaner approach.
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c index e48afd620d7e..077fe908bf86 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c @@ -651,6 +651,7 @@ struct mlx5_ttc_table *mlx5_create_inner_ttc_table(struct mlx5_core_dev *dev, MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, inner_l4_type); break; default: + kvfree(ttc); return ERR_PTR(-EINVAL); } @@ -729,6 +730,7 @@ struct mlx5_ttc_table *mlx5_create_ttc_table(struct mlx5_core_dev *dev, MLX5_CAP_NIC_RX_FT_FIELD_SUPPORT_2(dev, outer_l4_type); break; default: + kvfree(ttc); return ERR_PTR(-EINVAL); }
Free ttc table memory when unsupported ttc_type is passed, to avoid memory leak on the default error path in mlx5_create_inner_ttc_table() and mlx5_create_ttc_table(). Fixes: 137f3d50ad2a ("net/mlx5: Support matching on l4_type for ttc_table") Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com> --- drivers/net/ethernet/mellanox/mlx5/core/lib/fs_ttc.c | 2 ++ 1 file changed, 2 insertions(+)