From: Yu Kuai <yukuai1@huaweicloud.com>
To: Luis Chamberlain <mcgrof@kernel.org>, linan666@huaweicloud.com
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
linan122@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com,
yangerkun@huawei.com, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] scsi: sd: unregister device if device_add_disk() failed in sd_probe()
Date: Fri, 22 Dec 2023 16:27:16 +0800 [thread overview]
Message-ID: <78fb6d82-c50a-8fea-ae6d-551fd35656bf@huaweicloud.com> (raw)
In-Reply-To: <ZYUxZc/my2v6UfFJ@bombadil.infradead.org>
Hi,
在 2023/12/22 14:49, Luis Chamberlain 写道:
> On Fri, Dec 08, 2023 at 04:23:35PM +0800, linan666@huaweicloud.com wrote:
>> From: Li Nan <linan122@huawei.com>
>>
>> "if device_add() succeeds, you should call device_del() when you want to
>> get rid of it."
>>
>> In sd_probe(), device_add_disk() fails when device_add() has already
>> succeeded, so change put_device() to device_unregister() to ensure device
>> resources are released.
>>
>> Fixes: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()")
>> Signed-off-by: Li Nan <linan122@huawei.com>
>
> Nacked-by: Luis Chamberlain <mcgrof@kernel.org>
>
>> ---
>> drivers/scsi/sd.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>> index 542a4bbb21bc..d81cbeee06eb 100644
>> --- a/drivers/scsi/sd.c
>> +++ b/drivers/scsi/sd.c
>> @@ -3736,7 +3736,7 @@ static int sd_probe(struct device *dev)
>>
>> error = device_add_disk(dev, gd, NULL);
>> if (error) {
>> - put_device(&sdkp->disk_dev);
>> + device_unregister(&sdkp->disk_dev);
>> put_disk(gd);
>> goto out;
>> }
>
> This is incorrect, device_unregister() calls:
>
> void device_unregister(struct device *dev)
> {
> pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
> device_del(dev);
> put_device(dev);
> }
>
> So you're adding what you believe to be a correct missing device_del().
> But what you missed is that if device_add_disk() fails then device_add()
> did not succeed because the new code we have in the kernel *today* unwinds
> this for us now.
I'm confused here, there are two device here, one is 'sdkp->disk_dev',
one is gendisk->part0->bd_device, and the order in which they
initialize:
sd_probe
device_add(&sdkp->disk_dev) -> succeed
device_add_disk -> failed, and device_add(bd_device) did not succeed
put_device(&sdkp->disk_dev) -> device_del is missed
I don't see that if device_add_disk() fail, device_del() for
'sdkp->disk_dev'is called from anywhere. Do I missing anything?
Thanks,
Kuai
>
> What you missed is that in today's code inside device_add_disk(), if
> device_add() succeeeds we now unwind and call device_del() for the
> device for you. And so, quoting the next sentence you took from
> device_add():
>
> "If device_add() has *not* succeeded, use *only* put_device() to drop the
> reference count."
>
> Please do reference in the future a crash dump / or explain how you
> reached your conclusions if you do not have a crash dump to prove an
> issue. Specially if you are suggesting it Fixes a commit.
>
> Luis
>
> .
>
next prev parent reply other threads:[~2023-12-22 8:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 8:23 linan666
2023-12-22 6:49 ` Luis Chamberlain
2023-12-22 8:27 ` Yu Kuai [this message]
2024-01-29 17:46 ` Luis Chamberlain
2024-01-30 1:30 ` Yu Kuai
2024-01-29 13:26 ` Li Nan
2024-02-22 9:24 ` Li Nan
2024-04-01 1:31 ` Yu Kuai
2024-04-01 17:51 ` Bart Van Assche
2024-04-02 0:16 ` Damien Le Moal
2024-04-01 17:49 ` Bart Van Assche
2024-04-02 1:48 ` Martin K. Petersen
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=78fb6d82-c50a-8fea-ae6d-551fd35656bf@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=houtao1@huawei.com \
--cc=jejb@linux.ibm.com \
--cc=linan122@huawei.com \
--cc=linan666@huaweicloud.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mcgrof@kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--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®