diff mbox series

RDMA/siw: fix refcounting leak in siw_create_qp()

Message ID 20220118091104.GA11671@kili (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series RDMA/siw: fix refcounting leak in siw_create_qp() | expand

Commit Message

Dan Carpenter Jan. 18, 2022, 9:11 a.m. UTC
The atomic_inc() needs to be paired with an atomic_dec() on the error
path.

Fixes: 514aee660df4 ("RDMA: Globally allocate and release QP memory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Leon Romanovsky Jan. 18, 2022, 9:56 a.m. UTC | #1
On Tue, Jan 18, 2022 at 12:11:04PM +0300, Dan Carpenter wrote:
> The atomic_inc() needs to be paired with an atomic_dec() on the error
> path.
> 
> Fixes: 514aee660df4 ("RDMA: Globally allocate and release QP memory")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Bernard Metzler Jan. 18, 2022, 11:38 a.m. UTC | #2
> -----Original Message-----
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Sent: Tuesday, 18 January 2022 10:11
> To: Bernard Metzler <BMT@zurich.ibm.com>; Leon Romanovsky
> <leonro@nvidia.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>; Gal Pressman <galpress@amazon.com>;
> Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>; linux-
> rdma@vger.kernel.org; kernel-janitors@vger.kernel.org
> Subject: [EXTERNAL] [PATCH] RDMA/siw: fix refcounting leak in
> siw_create_qp()
> 
> The atomic_inc() needs to be paired with an atomic_dec() on the error
> path.
> 
> Fixes: 514aee660df4 ("RDMA: Globally allocate and release QP memory")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/sw/siw/siw_verbs.c
> b/drivers/infiniband/sw/siw/siw_verbs.c
> index a3dd2cb6d5c9..54ef367b074a 100644
> --- a/drivers/infiniband/sw/siw/siw_verbs.c
> +++ b/drivers/infiniband/sw/siw/siw_verbs.c
> @@ -313,7 +313,8 @@ int siw_create_qp(struct ib_qp *ibqp, struct
> ib_qp_init_attr *attrs,
> 
>  	if (atomic_inc_return(&sdev->num_qp) > SIW_MAX_QP) {
>  		siw_dbg(base_dev, "too many QP's\n");
> -		return -ENOMEM;
> +		rv = -ENOMEM;
> +		goto err_atomic;
>  	}
>  	if (attrs->qp_type != IB_QPT_RC) {
>  		siw_dbg(base_dev, "only RC QP's supported\n");
> --
> 2.20.1

Good catch, thank you!

Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
Jason Gunthorpe Jan. 28, 2022, 4:40 p.m. UTC | #3
On Tue, Jan 18, 2022 at 12:11:04PM +0300, Dan Carpenter wrote:
> The atomic_inc() needs to be paired with an atomic_dec() on the error
> path.
> 
> Fixes: 514aee660df4 ("RDMA: Globally allocate and release QP memory")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
> Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
> ---
>  drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied to for-rc, thanks

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c
index a3dd2cb6d5c9..54ef367b074a 100644
--- a/drivers/infiniband/sw/siw/siw_verbs.c
+++ b/drivers/infiniband/sw/siw/siw_verbs.c
@@ -313,7 +313,8 @@  int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
 
 	if (atomic_inc_return(&sdev->num_qp) > SIW_MAX_QP) {
 		siw_dbg(base_dev, "too many QP's\n");
-		return -ENOMEM;
+		rv = -ENOMEM;
+		goto err_atomic;
 	}
 	if (attrs->qp_type != IB_QPT_RC) {
 		siw_dbg(base_dev, "only RC QP's supported\n");