scsi: sd: Unregister device if device_add_disk() failed in sd_probe()

[ Upstream commit 0296bea01c ]

"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: 2a7a891f4c ("scsi: sd: Add error handling support for add_disk()")
Signed-off-by: Li Nan <linan122@huawei.com>
Link: https://lore.kernel.org/r/20231208082335.1754205-1-linan666@huaweicloud.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Li Nan 2023-12-08 16:23:35 +08:00 committed by Greg Kroah-Hartman
parent 6e0745e738
commit d3cd8b9028
1 changed files with 1 additions and 1 deletions

View File

@ -3757,7 +3757,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;
}