From: Michael Baum Date: Tue, 31 Aug 2021 20:39:41 +0000 (+0300) Subject: compress/mlx5: fix leak on QP setup failure X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=12b253ee876f3e687524a12fd670ffc65f0aed4d;p=dpdk.git compress/mlx5: fix leak on QP setup failure The QP setup function allocates buffer for its opaque MR and register it into MR structure. After buffer allocation and before MR registration, it tries allocate MR Btree. When the MR Btree allocation fails, the buffer was not freed what caused a memory leak. Allocate the MR Btree before buffer alloction. Fixes: 0165bccdb45f ("compress/mlx5: add memory region management") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- diff --git a/drivers/compress/mlx5/mlx5_compress.c b/drivers/compress/mlx5/mlx5_compress.c index 883e720ec1..c5e0a83a8c 100644 --- a/drivers/compress/mlx5/mlx5_compress.c +++ b/drivers/compress/mlx5/mlx5_compress.c @@ -207,6 +207,13 @@ mlx5_compress_qp_setup(struct rte_compressdev *dev, uint16_t qp_id, return -rte_errno; } dev->data->queue_pairs[qp_id] = qp; + if (mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N, + priv->dev_config.socket_id)) { + DRV_LOG(ERR, "Cannot allocate MR Btree for qp %u.", + (uint32_t)qp_id); + rte_errno = ENOMEM; + goto err; + } opaq_buf = rte_calloc(__func__, (size_t)1 << log_ops_n, sizeof(struct mlx5_gga_compress_opaque), sizeof(struct mlx5_gga_compress_opaque)); @@ -215,13 +222,6 @@ mlx5_compress_qp_setup(struct rte_compressdev *dev, uint16_t qp_id, rte_errno = ENOMEM; goto err; } - if (mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N, - priv->dev_config.socket_id)) { - DRV_LOG(ERR, "Cannot allocate MR Btree for qp %u.", - (uint32_t)qp_id); - rte_errno = ENOMEM; - goto err; - } qp->entries_n = 1 << log_ops_n; qp->socket_id = socket_id; qp->qp_id = qp_id;