@@ -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);
}
}
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(-)