linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: add put_device() call when device_add() fails in device_add_disk()
@ 2024-02-21 22:01 Alfredo Cruz
  2024-02-22  9:22 ` Yu Kuai
  0 siblings, 1 reply; 2+ messages in thread
From: Alfredo Cruz @ 2024-02-21 22:01 UTC (permalink / raw)
  To: axboe, linux-block, linux-kernel; +Cc: Alfredo Cruz

When device_add() fails, put_device() should called for cleanup.
Added this call before the jump to out_free_ext_minor to not
interfere with device_del() on error paths where deivce_add() succeeded

Signed-off-by: Alfredo Cruz <alfredo.carlon@gmail.com>
---
 block/genhd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index d74fb5b4ae68..5a231fb075bd 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -456,8 +456,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
 	if (!(disk->flags & GENHD_FL_HIDDEN))
 		ddev->devt = MKDEV(disk->major, disk->first_minor);
 	ret = device_add(ddev);
-	if (ret)
+	if (ret) {
+		put_device(ddev);
 		goto out_free_ext_minor;
+	}
 
 	ret = disk_alloc_events(disk);
 	if (ret)
-- 
2.43.2


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

* Re: [PATCH] block: add put_device() call when device_add() fails in device_add_disk()
  2024-02-21 22:01 [PATCH] block: add put_device() call when device_add() fails in device_add_disk() Alfredo Cruz
@ 2024-02-22  9:22 ` Yu Kuai
  0 siblings, 0 replies; 2+ messages in thread
From: Yu Kuai @ 2024-02-22  9:22 UTC (permalink / raw)
  To: Alfredo Cruz, axboe, linux-block, linux-kernel, yukuai (C)

Hi,

在 2024/02/22 6:01, Alfredo Cruz 写道:
> When device_add() fails, put_device() should called for cleanup.
> Added this call before the jump to out_free_ext_minor to not
> interfere with device_del() on error paths where deivce_add() succeeded
> 
> Signed-off-by: Alfredo Cruz <alfredo.carlon@gmail.com>
> ---
>   block/genhd.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index d74fb5b4ae68..5a231fb075bd 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -456,8 +456,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
>   	if (!(disk->flags & GENHD_FL_HIDDEN))
>   		ddev->devt = MKDEV(disk->major, disk->first_minor);
>   	ret = device_add(ddev);
> -	if (ret)
> +	if (ret) {
> +		put_device(ddev);
>   		goto out_free_ext_minor;
> +	}

This is wrong, gendisk is allocated by caller, and caller is responsible
to free the gendisk, as you can see in many callers.

Thanks,
Kuai

>   
>   	ret = disk_alloc_events(disk);
>   	if (ret)
> 


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

end of thread, other threads:[~2024-02-22  9:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-21 22:01 [PATCH] block: add put_device() call when device_add() fails in device_add_disk() Alfredo Cruz
2024-02-22  9:22 ` Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).