mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: Alfredo Cruz <alfredo.carlon@gmail.com>,
	axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] block: add put_device() call when device_add() fails in device_add_disk()
Date: Thu, 22 Feb 2024 17:22:20 +0800	[thread overview]
Message-ID: <bf8659c5-8cfe-fd0e-3b59-c07cf1f48a87@huaweicloud.com> (raw)
In-Reply-To: <20240221220141.32316-1-alfredo.carlon@gmail.com>

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


      reply	other threads:[~2024-02-22  9:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 22:01 Alfredo Cruz
2024-02-22  9:22 ` Yu Kuai [this message]

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=bf8659c5-8cfe-fd0e-3b59-c07cf1f48a87@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=alfredo.carlon@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yukuai3@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®