All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix memory leak in disk_register_independent_access_ranges
@ 2022-01-20 10:10 Miaoqian Lin
  2022-01-21  9:57 ` Damien Le Moal
  2022-01-21 17:48 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-01-20 10:10 UTC (permalink / raw)
  To: Jens Axboe, Hannes Reinecke, Keith Busch, Martin K. Petersen,
	Damien Le Moal, linux-block, linux-kernel
  Cc: linmq006

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add()

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix this issue by adding kobject_put().
Callback function blk_ia_ranges_sysfs_release() in kobject_put()
can handle the pointer "iars" properly.

Fixes: a2247f19ee1c ("block: Add independent access ranges support")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 block/blk-ia-ranges.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-ia-ranges.c b/block/blk-ia-ranges.c
index b925f3db3ab7..18c68d8b9138 100644
--- a/block/blk-ia-ranges.c
+++ b/block/blk-ia-ranges.c
@@ -144,7 +144,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk,
 				   &q->kobj, "%s", "independent_access_ranges");
 	if (ret) {
 		q->ia_ranges = NULL;
-		kfree(iars);
+		kobject_put(&iars->kobj);
 		return ret;
 	}
 
-- 
2.17.1


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

* Re: [PATCH] block: fix memory leak in disk_register_independent_access_ranges
  2022-01-20 10:10 [PATCH] block: fix memory leak in disk_register_independent_access_ranges Miaoqian Lin
@ 2022-01-21  9:57 ` Damien Le Moal
  2022-01-21 17:48 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2022-01-21  9:57 UTC (permalink / raw)
  To: Miaoqian Lin, Jens Axboe, Hannes Reinecke, Keith Busch,
	Martin K. Petersen, Damien Le Moal, linux-block, linux-kernel

On 1/20/22 19:10, Miaoqian Lin wrote:
> kobject_init_and_add() takes reference even when it fails.
> According to the doc of kobject_init_and_add()
> 
>    If this function returns an error, kobject_put() must be called to
>    properly clean up the memory associated with the object.
> 
> Fix this issue by adding kobject_put().
> Callback function blk_ia_ranges_sysfs_release() in kobject_put()
> can handle the pointer "iars" properly.
> 
> Fixes: a2247f19ee1c ("block: Add independent access ranges support")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  block/blk-ia-ranges.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/blk-ia-ranges.c b/block/blk-ia-ranges.c
> index b925f3db3ab7..18c68d8b9138 100644
> --- a/block/blk-ia-ranges.c
> +++ b/block/blk-ia-ranges.c
> @@ -144,7 +144,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk,
>  				   &q->kobj, "%s", "independent_access_ranges");
>  	if (ret) {
>  		q->ia_ranges = NULL;
> -		kfree(iars);
> +		kobject_put(&iars->kobj);
>  		return ret;
>  	}
>  

Looks good.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] block: fix memory leak in disk_register_independent_access_ranges
  2022-01-20 10:10 [PATCH] block: fix memory leak in disk_register_independent_access_ranges Miaoqian Lin
  2022-01-21  9:57 ` Damien Le Moal
@ 2022-01-21 17:48 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-01-21 17:48 UTC (permalink / raw)
  To: Hannes Reinecke, linux-kernel, Miaoqian Lin, linux-block,
	Damien Le Moal, Martin K. Petersen, Keith Busch

On Thu, 20 Jan 2022 10:10:25 +0000, Miaoqian Lin wrote:
> kobject_init_and_add() takes reference even when it fails.
> According to the doc of kobject_init_and_add()
> 
>    If this function returns an error, kobject_put() must be called to
>    properly clean up the memory associated with the object.
> 
> Fix this issue by adding kobject_put().
> Callback function blk_ia_ranges_sysfs_release() in kobject_put()
> can handle the pointer "iars" properly.
> 
> [...]

Applied, thanks!

[1/1] block: fix memory leak in disk_register_independent_access_ranges
      commit: c321e650a45c4228cce1107680ac74e06f014906

Best regards,
-- 
Jens Axboe



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

end of thread, other threads:[~2022-01-21 17:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 10:10 [PATCH] block: fix memory leak in disk_register_independent_access_ranges Miaoqian Lin
2022-01-21  9:57 ` Damien Le Moal
2022-01-21 17:48 ` Jens Axboe

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.