Some types of QP may have no associated send CQ or recv CQ or neither, for example, XRC QP have neither of them. So there should be a check when locking/unlocking CQs to avoid accessind NULL pointer.
Fixes: c24583975044 ("libhns: Add verbs of qp support") Signed-off-by: Weihang Li liweihang@huawei.com --- providers/hns/hns_roce_u_hw_v2.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c index 0b2e31e..4d990dd 100644 --- a/providers/hns/hns_roce_u_hw_v2.c +++ b/providers/hns/hns_roce_u_hw_v2.c @@ -1425,14 +1425,20 @@ static void hns_roce_lock_cqs(struct ibv_qp *qp) struct hns_roce_cq *send_cq = to_hr_cq(qp->send_cq); struct hns_roce_cq *recv_cq = to_hr_cq(qp->recv_cq);
- if (send_cq == recv_cq) { - pthread_spin_lock(&send_cq->lock); - } else if (send_cq->cqn < recv_cq->cqn) { + if (send_cq && recv_cq) { + if (send_cq == recv_cq) { + pthread_spin_lock(&send_cq->lock); + } else if (send_cq->cqn < recv_cq->cqn) { + pthread_spin_lock(&send_cq->lock); + pthread_spin_lock(&recv_cq->lock); + } else { + pthread_spin_lock(&recv_cq->lock); + pthread_spin_lock(&send_cq->lock); + } + } else if (send_cq) { pthread_spin_lock(&send_cq->lock); + } else if (recv_cq) { pthread_spin_lock(&recv_cq->lock); - } else { - pthread_spin_lock(&recv_cq->lock); - pthread_spin_lock(&send_cq->lock); } }
@@ -1441,13 +1447,19 @@ static void hns_roce_unlock_cqs(struct ibv_qp *qp) struct hns_roce_cq *send_cq = to_hr_cq(qp->send_cq); struct hns_roce_cq *recv_cq = to_hr_cq(qp->recv_cq);
- if (send_cq == recv_cq) { - pthread_spin_unlock(&send_cq->lock); - } else if (send_cq->cqn < recv_cq->cqn) { - pthread_spin_unlock(&recv_cq->lock); - pthread_spin_unlock(&send_cq->lock); - } else { + if (send_cq && recv_cq) { + if (send_cq == recv_cq) { + pthread_spin_unlock(&send_cq->lock); + } else if (send_cq->cqn < recv_cq->cqn) { + pthread_spin_unlock(&recv_cq->lock); + pthread_spin_unlock(&send_cq->lock); + } else { + pthread_spin_unlock(&send_cq->lock); + pthread_spin_unlock(&recv_cq->lock); + } + } else if (send_cq) { pthread_spin_unlock(&send_cq->lock); + } else if (recv_cq) { pthread_spin_unlock(&recv_cq->lock); } }