[PATCH] IB/mlx5: Fix memory leak in GSI QP destroy error path

From: Prathamesh Deshpande

Date: Mon Mar 30 2026 - 20:54:05 EST


In mlx5_ib_destroy_gsi(), if the call to ib_destroy_qp() fails for
the hardware receive QP (gsi->rx_qp), the function currently returns
early. This results in a memory leak of the software resources
(outstanding_wrs, tx_qps) and the 'gsi' structure itself.

Align the GSI destroy path with the 'best-effort' cleanup pattern. Even
if the hardware fails to release the QP, proceed with the software
cleanup to prevent orphan allocations.

Fixes: d16e91daf446 ("IB/mlx5: Add GSI QP wrapper")

Signed-off-by: Prathamesh Deshpande <prathameshdeshpande7@xxxxxxxxx>
---
drivers/infiniband/hw/mlx5/gsi.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/gsi.c b/drivers/infiniband/hw/mlx5/gsi.c
index b2e2a219639d..2272236e7f7f 100644
--- a/drivers/infiniband/hw/mlx5/gsi.c
+++ b/drivers/infiniband/hw/mlx5/gsi.c
@@ -175,11 +175,9 @@ int mlx5_ib_destroy_gsi(struct mlx5_ib_qp *mqp)
int ret;

ret = ib_destroy_qp(gsi->rx_qp);
- if (ret) {
+ if (ret)
mlx5_ib_warn(dev, "unable to destroy hardware GSI QP. error %d\n",
ret);
- return ret;
- }
dev->devr.ports[port_num - 1].gsi = NULL;
gsi->rx_qp = NULL;

--
2.43.0