diff mbox series

[1/6] net/mlx5: fix shared device context creation error flow

Message ID 20210831203732.3411134-2-michaelba@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers show
Series mlx5: some independent fixes | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Aug. 31, 2021, 8:37 p.m. UTC
In shared device context creation, there are two validations after MR
btree memory allocation.

When one of them fails, the MR btree memory was not freed what caused a
memory leak.

Free it.

Fixes: 632f0f19056f ("net/mlx5: manage shared counters in three-level table")
Cc: stable@dpdk.org

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/net/mlx5/mlx5.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Raslan Darawsheh Sept. 5, 2021, 8:46 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Michael Baum <michaelba@nvidia.com>
> Sent: Tuesday, August 31, 2021 11:37 PM
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Raslan Darawsheh
> <rasland@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> stable@dpdk.org
> Subject: [PATCH 1/6] net/mlx5: fix shared device context creation error flow
How about something like this:
fix memory leak in the shared device context creation
> 
> In shared device context creation, there are two validations after MR
> btree memory allocation.
> 
> When one of them fails, the MR btree memory was not freed what caused a
> memory leak.
> 
> Free it.
How about changing it to something like this:

In shared device context creation, there is a missing validation when one of
the btree memory allocation fails that will cause a memory leak.

This adds a proper check to clean resources in case of failure.

> 
> Fixes: 632f0f19056f ("net/mlx5: manage shared counters in three-level
> table")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Michael Baum <michaelba@nvidia.com>
> ---
>  drivers/net/mlx5/mlx5.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
> index f84e061fe7..f0ec2d1279 100644
> --- a/drivers/net/mlx5/mlx5.c
> +++ b/drivers/net/mlx5/mlx5.c
> @@ -1254,6 +1254,8 @@ mlx5_alloc_shared_dev_ctx(const struct
> mlx5_dev_spawn_data *spawn,
>  	MLX5_ASSERT(sh);
>  	if (sh->cnt_id_tbl)
>  		mlx5_l3t_destroy(sh->cnt_id_tbl);
> +	if (sh->share_cache.cache.table)
> +		mlx5_mr_btree_free(&sh->share_cache.cache);
>  	if (sh->tis)
>  		claim_zero(mlx5_devx_cmd_destroy(sh->tis));
>  	if (sh->td)
> --
> 2.25.1
diff mbox series

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index f84e061fe7..f0ec2d1279 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1254,6 +1254,8 @@  mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
 	MLX5_ASSERT(sh);
 	if (sh->cnt_id_tbl)
 		mlx5_l3t_destroy(sh->cnt_id_tbl);
+	if (sh->share_cache.cache.table)
+		mlx5_mr_btree_free(&sh->share_cache.cache);
 	if (sh->tis)
 		claim_zero(mlx5_devx_cmd_destroy(sh->tis));
 	if (sh->td)