From: Leon Romanovsky <leon@kernel.org>
To: Yongzhi Liu <lyz_cs@pku.edu.cn>
Cc: jgg@ziepe.ca, yishaih@mellanox.com, linux-rdma@vger.kernel.org,
linux-kernel@vger.kernel.org, fuyq@stu.pku.edu.cn
Subject: Re: [PATCH] RDMA/mlx5: Fix memory leak
Date: Sun, 13 Mar 2022 21:06:56 +0200 [thread overview]
Message-ID: <Yi5A0AkiVTLfkYFM@unreal> (raw)
In-Reply-To: <1647018361-18266-1-git-send-email-lyz_cs@pku.edu.cn>
On Fri, Mar 11, 2022 at 09:06:01AM -0800, Yongzhi Liu wrote:
> [why]
> xa_insert is failed, so caller of subscribe_event_xa_alloc
> cannot call other function to free obj_event. Therefore,
> Resource release is needed on the error handling path to
> prevent memory leak.
>
> [how]
> Fix this by adding kfree on the error handling path.
>
> Fixes: 7597385 ("IB/mlx5: Enable subscription for device events over DEVX")
>
> Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
> ---
> drivers/infiniband/hw/mlx5/devx.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
The change itself is correct one, but commit message needs to be improved.
Something like that:
------------------------------------------------------------------
[PATCH] RDMA/mlx5: Fix memory leak in error subscribe event routine
In case second xa_insert() fails, the obj_event is not released.
Fix the error unwind flow to free that memory to avoid memory leak.
Fixes: 7597385 ("IB/mlx5: Enable subscription for device events over DEVX")
Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
-------------------------------------------------------------------
>
> diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
> index 08b7f6b..15c0884 100644
> --- a/drivers/infiniband/hw/mlx5/devx.c
> +++ b/drivers/infiniband/hw/mlx5/devx.c
> @@ -1886,8 +1886,10 @@ subscribe_event_xa_alloc(struct mlx5_devx_event_table *devx_event_table,
> key_level2,
> obj_event,
> GFP_KERNEL);
> - if (err)
> + if (err) {
> + kfree(obj_event);
> return err;
> + }
> INIT_LIST_HEAD(&obj_event->obj_sub_list);
> }
>
> --
> 2.7.4
>
next prev parent reply other threads:[~2022-03-13 19:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 17:06 [PATCH] RDMA/mlx5: Fix memory leak Yongzhi Liu
2022-03-13 19:06 ` Leon Romanovsky [this message]
2022-03-14 3:10 ` [PATCH v2] RDMA/mlx5: Fix memory leak in error subscribe event routine Yongzhi Liu
2022-03-14 23:45 ` [PATCH] RDMA/mlx5: Fix memory leak Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yi5A0AkiVTLfkYFM@unreal \
--to=leon@kernel.org \
--cc=fuyq@stu.pku.edu.cn \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=lyz_cs@pku.edu.cn \
--cc=yishaih@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.