All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/mlx5: Fix memory leak
@ 2022-03-11 17:06 Yongzhi Liu
  2022-03-13 19:06 ` Leon Romanovsky
  2022-03-14 23:45 ` [PATCH] RDMA/mlx5: Fix memory leak Jason Gunthorpe
  0 siblings, 2 replies; 4+ messages in thread
From: Yongzhi Liu @ 2022-03-11 17:06 UTC (permalink / raw)
  To: leon, jgg, yishaih; +Cc: linux-rdma, linux-kernel, fuyq, Yongzhi Liu

[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(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] RDMA/mlx5: Fix memory leak
  2022-03-11 17:06 [PATCH] RDMA/mlx5: Fix memory leak Yongzhi Liu
@ 2022-03-13 19:06 ` Leon Romanovsky
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2022-03-13 19:06 UTC (permalink / raw)
  To: Yongzhi Liu; +Cc: jgg, yishaih, linux-rdma, linux-kernel, fuyq

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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] RDMA/mlx5: Fix memory leak in error subscribe event routine
  2022-03-13 19:06 ` Leon Romanovsky
@ 2022-03-14  3:10   ` Yongzhi Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Yongzhi Liu @ 2022-03-14  3:10 UTC (permalink / raw)
  To: leon; +Cc: yishaih, linux-rdma, linux-kernel, jgg, Yongzhi Liu

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>
---
 drivers/infiniband/hw/mlx5/devx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] RDMA/mlx5: Fix memory leak
  2022-03-11 17:06 [PATCH] RDMA/mlx5: Fix memory leak Yongzhi Liu
  2022-03-13 19:06 ` Leon Romanovsky
@ 2022-03-14 23:45 ` Jason Gunthorpe
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2022-03-14 23:45 UTC (permalink / raw)
  To: Yongzhi Liu; +Cc: leon, yishaih, linux-rdma, linux-kernel, fuyq

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>
> Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
> ---
>  drivers/infiniband/hw/mlx5/devx.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied to for-next with Leon's commit message

Thanks,
Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-14 23:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 17:06 [PATCH] RDMA/mlx5: Fix memory leak Yongzhi Liu
2022-03-13 19:06 ` Leon Romanovsky
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

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.