Skip to contentSkip to conversation

RDMA/siw: fix refcounting leak in siw_create_qp()

PATCH Applied Dan Carpenter 4 participants 4 messages Jan 18, 2022 – Jan 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_verbs.c +2 -1
index a3dd2cb6d5c9..54ef367b074a 100644
@@ -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");
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 35 lines

-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, 18 January 2022 10:11
To: Bernard Metzler <[email protected]>; Leon Romanovsky <[email protected]>
Cc: Jason Gunthorpe <[email protected]>; Gal Pressman <[email protected]>; Dennis Dalessandro <[email protected]>; linux- [email protected]; [email protected]
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")
---
 drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_verbs.c +2 -1
index a3dd2cb6d5c9..54ef367b074a 100644
@@ -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) {
Quoted 3 lines

siw_dbg(base_dev, "only RC QP's supported\n");
--
2.20.1

Good catch, thank you!

maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

The atomic_inc() needs to be paired with an atomic_dec() on the error path.

Fixes 514aee660df4 ("RDMA: Globally allocate and release QP memory")
---
 drivers/infiniband/sw/siw/siw_verbs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to for-rc, thanks

Jason