Skip to contentSkip to conversation

compress/mlx5: fix QP setup error flow

PATCH Applied Michael Baum 3 participants 3 messages Aug 31, 2021 – Sep 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compress/mlx5: fix QP setup error flow

The QP setup function allocates buffer for its opaque MR and register it into MR structure.

After buffer alloction 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")
---
 drivers/compress/mlx5/mlx5_compress.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/compress/mlx5/mlx5_compress.c +7 -7
index 883e720ec1..c5e0a83a8c 100644
@@ -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;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

From: Michael Baum <[email protected]>

Quoted 12 lines

Sent: Tuesday, August 31, 2021 11:40 PM
To: [email protected]
Cc: Matan Azrad <[email protected]>; [email protected]
Subject: [PATCH] compress/mlx5: fix QP setup error flow

The QP setup function allocates buffer for its opaque MR and register it into MR structure.

After buffer alloction 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.

Quoted 6 lines

Allocate the MR Btree before buffer alloction.

Fixes 0165bccdb45f ("compress/mlx5: add memory region management")
Applied
#2 lore raw
Quoted 8 lines
Quoted 1 line

The QP setup function allocates buffer for its opaque MR and register it

into

Quoted 6 lines

MR structure.

After buffer alloction 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.

Quoted 7 lines
Quoted 6 lines

Allocate the MR Btree before buffer alloction.

Fixes 0165bccdb45f ("compress/mlx5: add memory region management")

Applied to dpdk-next-crypto

Thanks,