diff mbox series

[net,v2] net/mlx5: DR, fix memory leak in mlx5dr_cmd_create_reformat_ctx

Message ID 20230705121527.2230772-1-shaozhengchao@huawei.com (mailing list archive)
State Not Applicable
Headers show
Series [net,v2] net/mlx5: DR, fix memory leak in mlx5dr_cmd_create_reformat_ctx | expand

Commit Message

shaozhengchao July 5, 2023, 12:15 p.m. UTC
when mlx5_cmd_exec failed in mlx5dr_cmd_create_reformat_ctx, the memory
pointed by 'in' is not released, which will cause memory leak. Move memory
release after mlx5_cmd_exec.

Fixes: 1d9186476e12 ("net/mlx5: DR, Add direct rule command utilities")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
v2: goto label 'err_free_in' to free 'in'
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky July 5, 2023, 12:19 p.m. UTC | #1
On Wed, Jul 05, 2023 at 08:15:27PM +0800, Zhengchao Shao wrote:
> when mlx5_cmd_exec failed in mlx5dr_cmd_create_reformat_ctx, the memory
> pointed by 'in' is not released, which will cause memory leak. Move memory
> release after mlx5_cmd_exec.
> 
> Fixes: 1d9186476e12 ("net/mlx5: DR, Add direct rule command utilities")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
> v2: goto label 'err_free_in' to free 'in'
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
index 7491911ebcb5..8c2a34a0d6be 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_cmd.c
@@ -564,11 +564,12 @@  int mlx5dr_cmd_create_reformat_ctx(struct mlx5_core_dev *mdev,
 
 	err = mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
 	if (err)
-		return err;
+		goto err_free_in;
 
 	*reformat_id = MLX5_GET(alloc_packet_reformat_context_out, out, packet_reformat_id);
-	kvfree(in);
 
+err_free_in:
+	kvfree(in);
 	return err;
 }