diff mbox series

[V2,1/3] RDMA/siw: Balance the reference of cep->kref in the error path

Message ID 20230821084743.6489-2-guoqing.jiang@linux.dev (mailing list archive)
State Superseded
Headers show
Series Misc changes for siw | expand

Commit Message

Guoqing Jiang Aug. 21, 2023, 8:47 a.m. UTC
The siw_connect can go to err in below after cep is allocated successfully:

1. If siw_cm_alloc_work returns failure. In this case socket is not
assoicated with cep so siw_cep_put can't be called by siw_socket_disassoc.
We need to call siw_cep_put twice since cep->kref is increased once after
it was initialized.

2. If siw_cm_queue_work can't find a work, which means siw_cep_get is not
called in siw_cm_queue_work, so cep->kref is increased twice by siw_cep_get
and when associate socket with cep after it was initialized. So we need to
call siw_cep_put three times (one in siw_socket_disassoc).

3. siw_send_mpareqrep returns error, this scenario is similar as 2.

So we need to remove one siw_cep_put in the error path.

Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
---
 drivers/infiniband/sw/siw/siw_cm.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Bernard Metzler Aug. 21, 2023, 12:06 p.m. UTC | #1
> -----Original Message-----
> From: Guoqing Jiang <guoqing.jiang@linux.dev>
> Sent: Monday, 21 August 2023 10:48
> To: Bernard Metzler <BMT@zurich.ibm.com>; jgg@ziepe.ca; leon@kernel.org
> Cc: linux-rdma@vger.kernel.org
> Subject: [EXTERNAL] [PATCH V2 1/3] RDMA/siw: Balance the reference of cep-
> >kref in the error path
> 
> The siw_connect can go to err in below after cep is allocated successfully:
> 
> 1. If siw_cm_alloc_work returns failure. In this case socket is not
> assoicated with cep so siw_cep_put can't be called by siw_socket_disassoc.
> We need to call siw_cep_put twice since cep->kref is increased once after
> it was initialized.
> 
> 2. If siw_cm_queue_work can't find a work, which means siw_cep_get is not
> called in siw_cm_queue_work, so cep->kref is increased twice by siw_cep_get
> and when associate socket with cep after it was initialized. So we need to
> call siw_cep_put three times (one in siw_socket_disassoc).
> 
> 3. siw_send_mpareqrep returns error, this scenario is similar as 2.
> 
> So we need to remove one siw_cep_put in the error path.
> 
> Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
> Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
> ---
>  drivers/infiniband/sw/siw/siw_cm.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/infiniband/sw/siw/siw_cm.c
> b/drivers/infiniband/sw/siw/siw_cm.c
> index da530c0404da..a2605178f4ed 100644
> --- a/drivers/infiniband/sw/siw/siw_cm.c
> +++ b/drivers/infiniband/sw/siw/siw_cm.c
> @@ -1501,7 +1501,6 @@ int siw_connect(struct iw_cm_id *id, struct
> iw_cm_conn_param *params)
> 
>  		cep->cm_id = NULL;
>  		id->rem_ref(id);
> -		siw_cep_put(cep);
> 
>  		qp->cep = NULL;
>  		siw_cep_put(cep);
> --
> 2.35.3

That's correct, thank you!


Acked-by: Bernard Metzler <bmt@zurich.ibm.com>
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index da530c0404da..a2605178f4ed 100644
--- a/drivers/infiniband/sw/siw/siw_cm.c
+++ b/drivers/infiniband/sw/siw/siw_cm.c
@@ -1501,7 +1501,6 @@  int siw_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 
 		cep->cm_id = NULL;
 		id->rem_ref(id);
-		siw_cep_put(cep);
 
 		qp->cep = NULL;
 		siw_cep_put(cep);