[PATCH] RDMA/rxe: Fix an error handling path in rxe_get_mcg()

Christophe JAILLET posted 1 patch 3 years, 11 months ago
drivers/infiniband/sw/rxe/rxe_mcast.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] RDMA/rxe: Fix an error handling path in rxe_get_mcg()
Posted by Christophe JAILLET 3 years, 11 months ago
The commit in the Fixes tag has shuffled some code.
Now 'mcg_num' is incremented before the kzalloc(). So if the memory
allocation fails, this increment must be undone.

Fixes: a926a903b7dc ("RDMA/rxe: Do not call dev_mc_add/del() under a spinlock")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/infiniband/sw/rxe/rxe_mcast.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c
index 873a9b10307c..86cc2e18a7fd 100644
--- a/drivers/infiniband/sw/rxe/rxe_mcast.c
+++ b/drivers/infiniband/sw/rxe/rxe_mcast.c
@@ -206,8 +206,10 @@ static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid)
 
 	/* speculative alloc of new mcg */
 	mcg = kzalloc(sizeof(*mcg), GFP_KERNEL);
-	if (!mcg)
-		return ERR_PTR(-ENOMEM);
+	if (!mcg) {
+		err = -ENOMEM;
+		goto err_dec;
+	}
 
 	spin_lock_bh(&rxe->mcg_lock);
 	/* re-check to see if someone else just added it */
-- 
2.34.1
Re: [PATCH] RDMA/rxe: Fix an error handling path in rxe_get_mcg()
Posted by Jason Gunthorpe 3 years, 11 months ago
On Sun, May 22, 2022 at 03:25:08PM +0200, Christophe JAILLET wrote:
> The commit in the Fixes tag has shuffled some code.
> Now 'mcg_num' is incremented before the kzalloc(). So if the memory
> allocation fails, this increment must be undone.
> 
> Fixes: a926a903b7dc ("RDMA/rxe: Do not call dev_mc_add/del() under a spinlock")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/infiniband/sw/rxe/rxe_mcast.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Applied to for-next, thanks

Jason