* [PATCH] rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp
@ 2022-09-07 3:36 Li zeming
2022-09-07 12:37 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Li zeming @ 2022-09-07 3:36 UTC (permalink / raw)
To: jgg, leon; +Cc: linux-rdma, linux-kernel, Li zeming
The pointer qp is assigned before it is used, it does not need to be
initialized and assigned.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
include/rdma/rdmavt_qp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h
index 2e58d5e6ac0e..2afc3300d618 100644
--- a/include/rdma/rdmavt_qp.h
+++ b/include/rdma/rdmavt_qp.h
@@ -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]);
--
2.18.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp
2022-09-07 3:36 [PATCH] rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp Li zeming
@ 2022-09-07 12:37 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2022-09-07 12:37 UTC (permalink / raw)
To: Li zeming; +Cc: jgg, linux-rdma, linux-kernel
On Wed, Sep 07, 2022 at 11:36:04AM +0800, Li zeming wrote:
> The pointer qp is assigned before it is used, it does not need to be
> initialized and assigned.
>
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
> include/rdma/rdmavt_qp.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h
> index 2e58d5e6ac0e..2afc3300d618 100644
> --- a/include/rdma/rdmavt_qp.h
> +++ b/include/rdma/rdmavt_qp.h
> @@ -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:
diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h
index 2e58d5e6ac0e..883c328e06b6 100644
--- a/include/rdma/rdmavt_qp.h
+++ b/include/rdma/rdmavt_qp.h
@@ -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;
}
/**
> --
> 2.18.2
>
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-07 12:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 3:36 [PATCH] rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp Li zeming
2022-09-07 12:37 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).