Re: [PATCH] scsi: sd: call device_del() if device_add_disk() fails
From: Christoph Hellwig
Date: Thu Mar 31 2022 - 05:13:54 EST
On Thu, Mar 31, 2022 at 11:07:45AM +0200, Fabio M. De Francesco wrote:
> If I don't misunderstand what you wrote, I think you mean something like
> the following changes:
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index a390679cf458..7a000a9a9dbe 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -3431,7 +3431,7 @@ static int sd_probe(struct device *dev)
> sdkp->disk_dev.class = &sd_disk_class;
> dev_set_name(&sdkp->disk_dev, "%s", dev_name(dev));
>
> - error = device_add(&sdkp->disk_dev);
> + error = device_register(&sdkp->disk_dev);
The device_initialize call about also need to go.
> if (error) {
> put_device(&sdkp->disk_dev);
.. and this put_device
> goto out;
> @@ -3474,7 +3474,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);
> goto out;
> }
.. and then the cleanup patch would need the same logic. But thinking
about it I don't think we actually can do that due to the split
unregistration. So I take my suggestion back.