Skip to contentSkip to conversation

rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp

PATCH In review Li zeming 2 participants 2 messages Sep 7, 2022 InfiniBand

lore
Share & tools
lore

Li zeming

author
#0 lore raw

PATCH 1/1 rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp

The pointer qp is assigned before it is used, it does not need to be initialized and assigned.

---
 include/rdma/rdmavt_qp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/rdmavt_qp.h +1 -1
index 2e58d5e6ac0e..2afc3300d618 100644
@@ -699,7 +699,7 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
 					    struct rvt_ibport *rvp,
 					    u32 qpn) __must_hold(RCU)
 {
-	struct rvt_qp *qp = NULL;
+	struct rvt_qp *qp;
 
 	if (unlikely(qpn <= 1)) {
 		qp = rcu_dereference(rvp->qp[qpn]);
Signature · 1 line
2.18.2
#1 lore raw
Quoted 13 lines · Li zeming

The pointer qp is assigned before it is used, it does not need to be initialized and assigned.

---
 include/rdma/rdmavt_qp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/rdmavt_qp.h +0 -0
index 2e58d5e6ac0e..2afc3300d618 100644

include/rdma/rdmavt_qp.h static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi, · line 705

Quoted 8 lines
include/rdma/rdmavt_qp.h +1 -1
@@ -699,7 +699,7 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
 					    struct rvt_ibport *rvp,
 					    u32 qpn) __must_hold(RCU)
 {
-	struct rvt_qp *qp = NULL;
+	struct rvt_qp *qp;
 
 	if (unlikely(qpn <= 1)) {
 		qp = rcu_dereference(rvp->qp[qpn]);

This function is completely wrong, most likely it never returns NULL otherwise, we would crash in "if (qp->ibqp.qp_num == qpn)" line.

The proper change will be something like this:

include/rdma/rdmavt_qp.h +11 -11
index 2e58d5e6ac0e..883c328e06b6 100644
@@ -699,19 +699,19 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
                                            struct rvt_ibport *rvp,
                                            u32 qpn) __must_hold(RCU)
 {
-       struct rvt_qp *qp = NULL;
+       struct rvt_qp *qp;
+       u32 n;
 
-       if (unlikely(qpn <= 1)) {
-               qp = rcu_dereference(rvp->qp[qpn]);
-       } else {
-               u32 n = hash_32(qpn, rdi->qp_dev->qp_table_bits);
+       if (unlikely(qpn <= 1))
+               return rcu_dereference(rvp->qp[qpn]);
 
-               for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp;
-                       qp = rcu_dereference(qp->next))
-                       if (qp->ibqp.qp_num == qpn)
-                               break;
-       }
-       return qp;
+       n = hash_32(qpn, rdi->qp_dev->qp_table_bits);
+
+       for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp;
+            qp = rcu_dereference(qp->next))
+               if (qp->ibqp.qp_num == qpn)
+                       return qp;
+       return NULL;
 }
 
 /**
Quoted 3 lines
Signature · 1 line
2.18.2