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
Delegated to: Netdev Maintainers
Headers show
Series net/mlx5: Fix NULL dereference and memory leak in ttc_table creation | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 2 blamed authors not CCed: mbloch@nvidia.com jianbol@nvidia.com; 2 maintainers not CCed: mbloch@nvidia.com jianbol@nvidia.com
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-04-16--03-00 (tests: 916)

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