]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/mlx5: Fix bind QP error cleanup flow
authorPatrisious Haddad <phaddad@nvidia.com>
Thu, 20 Feb 2025 06:47:10 +0000 (08:47 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2025 15:45:37 +0000 (16:45 +0100)
[ Upstream commit e1a0bdbdfdf08428f0ede5ae49c7f4139ac73ef5 ]

When there is a failure during bind QP, the cleanup flow destroys the
counter regardless if it is the one that created it or not, which is
problematic since if it isn't the one that created it, that counter could
still be in use.

Fix that by destroying the counter only if it was created during this call.

Fixes: 45842fc627c7 ("IB/mlx5: Support statistic q counter configuration")
Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Link: https://patch.msgid.link/25dfefddb0ebefa668c32e06a94d84e3216257cf.1740033937.git.leon@kernel.org
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/hw/mlx5/counters.c

index 8300ce6228350dde6d4efc6d79d122d843a8cef4..b049bba215790568aa62c9fdbe2fd86ec7480fad 100644 (file)
@@ -542,6 +542,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
                                   struct ib_qp *qp)
 {
        struct mlx5_ib_dev *dev = to_mdev(qp->device);
+       bool new = false;
        int err;
 
        if (!counter->id) {
@@ -556,6 +557,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
                        return err;
                counter->id =
                        MLX5_GET(alloc_q_counter_out, out, counter_set_id);
+               new = true;
        }
 
        err = mlx5_ib_qp_set_counter(qp, counter);
@@ -565,8 +567,10 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
        return 0;
 
 fail_set_counter:
-       mlx5_ib_counter_dealloc(counter);
-       counter->id = 0;
+       if (new) {
+               mlx5_ib_counter_dealloc(counter);
+               counter->id = 0;
+       }
 
        return err;
 }