diff mbox series

[v5,2/2] net/mlx5: Fix memory leak in error path of ttc creation

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

Commit Message

henry martin April 15, 2025, 12:41 p.m. UTC
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(+)

Comments

Mark Bloch April 15, 2025, 1:46 p.m. UTC | #1
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
henry martin April 16, 2025, 6:50 a.m. UTC | #2
> 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 mbox series

Patch

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