public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] ubi: block: fix memleak in ubiblock_create()
@ 2023-12-08  7:46 linan666
  2023-12-30  6:33 ` Li Nan
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: linan666 @ 2023-12-08  7:46 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr
  Cc: linux-mtd, linux-kernel, linan122, yukuai3, yi.zhang, houtao1,
	yangerkun

From: Li Nan <linan122@huawei.com>

If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
ubiblock_create(), but dev->gd has not been assigned yet at this time, and
'gd' will not be put anymore. Fix it by putting 'gd' directly.

Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
Changes in v2:
 - modify the description of the problem in log

 drivers/mtd/ubi/block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 309a42aeaa4c..654bd7372cd8 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
 	list_del(&dev->list);
 	idr_remove(&ubiblock_minor_idr, gd->first_minor);
 out_cleanup_disk:
-	put_disk(dev->gd);
+	put_disk(gd);
 out_free_tags:
 	blk_mq_free_tag_set(&dev->tag_set);
 out_free_dev:
-- 
2.39.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2023-12-08  7:46 [PATCH v2] ubi: block: fix memleak in ubiblock_create() linan666
@ 2023-12-30  6:33 ` Li Nan
  2024-01-29 13:27 ` Li Nan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Li Nan @ 2023-12-30  6:33 UTC (permalink / raw)
  To: linan666, richard, miquel.raynal, vigneshr
  Cc: linux-mtd, linux-kernel, yukuai3, yi.zhang, houtao1, yangerkun

friendly ping...

在 2023/12/8 15:46, linan666@huaweicloud.com 写道:
> From: Li Nan <linan122@huawei.com>
> 
> If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
> ubiblock_create(), but dev->gd has not been assigned yet at this time, and
> 'gd' will not be put anymore. Fix it by putting 'gd' directly.
> 
> Signed-off-by: Li Nan <linan122@huawei.com>
> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> ---
> Changes in v2:
>   - modify the description of the problem in log
> 
>   drivers/mtd/ubi/block.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
> index 309a42aeaa4c..654bd7372cd8 100644
> --- a/drivers/mtd/ubi/block.c
> +++ b/drivers/mtd/ubi/block.c
> @@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
>   	list_del(&dev->list);
>   	idr_remove(&ubiblock_minor_idr, gd->first_minor);
>   out_cleanup_disk:
> -	put_disk(dev->gd);
> +	put_disk(gd);
>   out_free_tags:
>   	blk_mq_free_tag_set(&dev->tag_set);
>   out_free_dev:

-- 
Thanks,
Nan


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2023-12-08  7:46 [PATCH v2] ubi: block: fix memleak in ubiblock_create() linan666
  2023-12-30  6:33 ` Li Nan
@ 2024-01-29 13:27 ` Li Nan
  2024-04-14  9:16 ` Markus Elfring
  2024-04-15  6:33 ` Dan Carpenter
  3 siblings, 0 replies; 7+ messages in thread
From: Li Nan @ 2024-01-29 13:27 UTC (permalink / raw)
  To: linan666, richard, miquel.raynal, vigneshr
  Cc: linux-mtd, linux-kernel, yukuai3, yi.zhang, houtao1, yangerkun

friendly ping ...

在 2023/12/8 15:46, linan666@huaweicloud.com 写道:
> From: Li Nan <linan122@huawei.com>
> 
> If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
> ubiblock_create(), but dev->gd has not been assigned yet at this time, and
> 'gd' will not be put anymore. Fix it by putting 'gd' directly.
> 
> Signed-off-by: Li Nan <linan122@huawei.com>
> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> ---
> Changes in v2:
>   - modify the description of the problem in log
> 
>   drivers/mtd/ubi/block.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
> index 309a42aeaa4c..654bd7372cd8 100644
> --- a/drivers/mtd/ubi/block.c
> +++ b/drivers/mtd/ubi/block.c
> @@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
>   	list_del(&dev->list);
>   	idr_remove(&ubiblock_minor_idr, gd->first_minor);
>   out_cleanup_disk:
> -	put_disk(dev->gd);
> +	put_disk(gd);
>   out_free_tags:
>   	blk_mq_free_tag_set(&dev->tag_set);
>   out_free_dev:

-- 
Thanks,
Nan


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2023-12-08  7:46 [PATCH v2] ubi: block: fix memleak in ubiblock_create() linan666
  2023-12-30  6:33 ` Li Nan
  2024-01-29 13:27 ` Li Nan
@ 2024-04-14  9:16 ` Markus Elfring
  2024-04-15  1:31   ` Li Nan
  2024-04-15  6:33 ` Dan Carpenter
  3 siblings, 1 reply; 7+ messages in thread
From: Markus Elfring @ 2024-04-14  9:16 UTC (permalink / raw)
  To: Li Nan, linux-mtd, kernel-janitors, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, Zhihao Cheng
  Cc: LKML, Hou Tao, Yang Erkun, Yu Kuai, Zhang Yi

Can it be nicer to use the term “memory leak” instead of “memleak”
in the patch subject?


…
> 'gd' will not be put anymore. Fix it by putting 'gd' directly.

Would the following wording variant be more desirable?

   … anymore.
   Thus pass the variable “gd” to a put_disk() call directly.


Would you like to add the tag “Fixes” accordingly?

Regards,
Markus

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2024-04-14  9:16 ` Markus Elfring
@ 2024-04-15  1:31   ` Li Nan
  0 siblings, 0 replies; 7+ messages in thread
From: Li Nan @ 2024-04-15  1:31 UTC (permalink / raw)
  To: Markus Elfring, linux-mtd, kernel-janitors, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, Zhihao Cheng
  Cc: LKML, Hou Tao, Yang Erkun, Yu Kuai, Zhang Yi



在 2024/4/14 17:16, Markus Elfring 写道:
> Can it be nicer to use the term “memory leak” instead of “memleak”
> in the patch subject?
> 
> 
> …
>> 'gd' will not be put anymore. Fix it by putting 'gd' directly.
> 
> Would the following wording variant be more desirable?
> 
>     … anymore.
>     Thus pass the variable “gd” to a put_disk() call directly.
> 
> 
> Would you like to add the tag “Fixes” accordingly?
> 

The patch has already been applied:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=adbf4c4954e33e623897058a617c583d65a177f6

Thank you very much for your suggestion. I will pay attention to them in
future patches.

> Regards,
> Markus
> .

-- 
Thanks,
Nan


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2023-12-08  7:46 [PATCH v2] ubi: block: fix memleak in ubiblock_create() linan666
                   ` (2 preceding siblings ...)
  2024-04-14  9:16 ` Markus Elfring
@ 2024-04-15  6:33 ` Dan Carpenter
  2024-04-18  9:07   ` Li Nan
  3 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2024-04-15  6:33 UTC (permalink / raw)
  To: linan666
  Cc: richard, miquel.raynal, vigneshr, linux-mtd, linux-kernel,
	linan122, yukuai3, yi.zhang, houtao1, yangerkun

On Fri, Dec 08, 2023 at 03:46:29PM +0800, linan666@huaweicloud.com wrote:
> From: Li Nan <linan122@huawei.com>
> 
> If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
> ubiblock_create(), but dev->gd has not been assigned yet at this time, and
> 'gd' will not be put anymore. Fix it by putting 'gd' directly.
> 

There is another invalid reference to dev->gd if blk_mq_alloc_tag_set()
fails.

	dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
                            ^^^^^^^

regards,
dan carpenter


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2] ubi: block: fix memleak in ubiblock_create()
  2024-04-15  6:33 ` Dan Carpenter
@ 2024-04-18  9:07   ` Li Nan
  0 siblings, 0 replies; 7+ messages in thread
From: Li Nan @ 2024-04-18  9:07 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: richard, miquel.raynal, vigneshr, linux-mtd, linux-kernel,
	linan122, yukuai3, yi.zhang, houtao1, yangerkun

Hi, dan,

在 2024/4/15 14:33, Dan Carpenter 写道:
> On Fri, Dec 08, 2023 at 03:46:29PM +0800, linan666@huaweicloud.com wrote:
>> From: Li Nan <linan122@huawei.com>
>>
>> If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
>> ubiblock_create(), but dev->gd has not been assigned yet at this time, and
>> 'gd' will not be put anymore. Fix it by putting 'gd' directly.
>>
> 
> There is another invalid reference to dev->gd if blk_mq_alloc_tag_set()
> fails.
> 
> 	dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
>                              ^^^^^^^
> 

You are really very careful! I will fix it later.

> regards,
> dan carpenter

-- 
Thanks,
Nan


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2024-04-18  9:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-08  7:46 [PATCH v2] ubi: block: fix memleak in ubiblock_create() linan666
2023-12-30  6:33 ` Li Nan
2024-01-29 13:27 ` Li Nan
2024-04-14  9:16 ` Markus Elfring
2024-04-15  1:31   ` Li Nan
2024-04-15  6:33 ` Dan Carpenter
2024-04-18  9:07   ` Li Nan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox