dr_destroy_cq() ignores the result of mlx5_core_destroy_cq() and frees the CQ buffer, doorbell record and struct mlx5dr_cq anyway. If DESTROY_CQ fails, the CQ may still exist in firmware and retain access to its buffer and doorbell record. mlx5_core_destroy_cq() also returns early in that case, without waiting for EQ handlers that may already hold a reference to the CQ. Keep the CQ and its buffer when DESTROY_CQ fails, as the regular mlx5_ib CQ destroy path does. A device in internal error is not affected, since the mlx5 core reports success for DESTROY_CQ in that state. Fixes: 297cccebdc5a ("net/mlx5: DR, Expose an internal API to issue RDMA operations") Assisted-by: LLM Signed-off-by: Yuho Choi --- This was found with a static analysis tool from ongoing, not yet published research, and confirmed by code inspection. It has not been reproduced on hardware. .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c index 79e3c29d1044e..8fc41adb4c756 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c @@ -1130,7 +1130,9 @@ static struct mlx5dr_cq *dr_create_cq(struct mlx5_core_dev *mdev, static void dr_destroy_cq(struct mlx5_core_dev *mdev, struct mlx5dr_cq *cq) { - mlx5_core_destroy_cq(mdev, &cq->mcq); + /* The device may still use an undestroyed CQ; keep it. */ + if (mlx5_core_destroy_cq(mdev, &cq->mcq)) + return; mlx5_wq_destroy(&cq->wq_ctrl); kfree(cq); } -- 2.43.0