Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f90813f authored by Jianglei Nie's avatar Jianglei Nie Committed by Greg Kroah-Hartman
Browse files

RDMA/hfi1: fix potential memory leak in setup_base_ctxt()

[ Upstream commit aa2a1df3a2c85f855af7d54466ac10bd48645d63 ]

setup_base_ctxt() allocates a memory chunk for uctxt->groups with
hfi1_alloc_ctxt_rcv_groups(). When init_user_ctxt() fails, uctxt->groups
is not released, which will lead to a memory leak.

We should release the uctxt->groups with hfi1_free_ctxt_rcv_groups()
when init_user_ctxt() fails.

Fixes: e87473bc ("IB/hfi1: Only set fd pointer when base context is completely initialized")
Link: https://lore.kernel.org/r/20220711070718.2318320-1-niejianglei2021@163.com


Signed-off-by: default avatarJianglei Nie <niejianglei2021@163.com>
Acked-by: default avatarDennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 11edf0bb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1224,8 +1224,10 @@ static int setup_base_ctxt(struct hfi1_filedata *fd,
		goto done;

	ret = init_user_ctxt(fd, uctxt);
	if (ret)
	if (ret) {
		hfi1_free_ctxt_rcv_groups(uctxt);
		goto done;
	}

	user_init(uctxt);