
Decrease pad refcnt by 1 in error flow of create qp/cq/srq. Fixes: 8c865c315c34 ("libhns: Add support for lock-free CQ") Fixes: 179f015e090d ("libhns: Add support for lock-free QP") Fixes: b38bae4b5b9e ("libhns: Add support for lock-free SRQ") Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com> --- providers/hns/hns_roce_u_verbs.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index b7d5f8d8e..62d42c98e 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -435,12 +435,9 @@ static int verify_cq_create_attr(struct ibv_cq_init_attr_ex *attr, return EOPNOTSUPP; } - if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) { - if (!pad) { - verbs_err(&context->ibv_ctx, "failed to check the pad of cq.\n"); - return EINVAL; - } - atomic_fetch_add(&pad->pd.refcount, 1); + if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD && !pad) { + verbs_err(&context->ibv_ctx, "failed to check the pad of cq.\n"); + return EINVAL; } attr->cqe = max_t(uint32_t, HNS_ROCE_MIN_CQE_NUM, @@ -510,6 +507,7 @@ static int exec_cq_create_cmd(struct ibv_context *context, static struct ibv_cq_ex *create_cq(struct ibv_context *context, struct ibv_cq_init_attr_ex *attr) { + struct hns_roce_pad *pad = to_hr_pad(attr->parent_domain); struct hns_roce_context *hr_ctx = to_hr_ctx(context); struct hns_roce_cq *cq; int ret; @@ -524,8 +522,10 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context, goto err; } - if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) + if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) { cq->parent_domain = attr->parent_domain; + atomic_fetch_add(&pad->pd.refcount, 1); + } ret = hns_roce_cq_spinlock_init(cq, attr); if (ret) @@ -563,6 +563,8 @@ err_db: err_buf: hns_roce_spinlock_destroy(&cq->hr_lock); err_lock: + if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) + atomic_fetch_sub(&pad->pd.refcount, 1); free(cq); err: if (ret < 0) @@ -899,6 +901,8 @@ err_destroy_lock: hns_roce_spinlock_destroy(&srq->hr_lock); err_free_srq: + if (pad) + atomic_fetch_sub(&pad->pd.refcount, 1); free(srq); err: @@ -1655,6 +1659,8 @@ err_cmd: err_buf: hns_roce_qp_spinlock_destroy(qp); err_spinlock: + if (pad) + atomic_fetch_sub(&pad->pd.refcount, 1); free(qp); err: if (ret < 0) -- 2.33.0