summaryrefslogtreecommitdiff
path: root/drivers/scsi
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2021-09-06 17:01:12 +0800
committerMartin K. Petersen <martin.petersen@oracle.com>2021-09-13 22:15:44 -0400
commit265dfe8ebbabae7959060bd1c3f75c2473b697ed (patch)
tree262bd64cc929b45002ca6a9ac9c898169d66067a /drivers/scsi
parente4953a93104c1fb1ef7989541f9867cc276467f9 (diff)
scsi: sd: Free scsi_disk device via put_device()
After a device is initialized via device_initialize() it should be freed via put_device(). sd_probe() currently gets this wrong, fix it up. Link: https://lore.kernel.org/r/20210906090112.531442-1-ming.lei@redhat.com Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/sd.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cbd9999f93a6..a8039beb5a02 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3401,15 +3401,16 @@ static int sd_probe(struct device *dev)
}
device_initialize(&sdkp->dev);
- sdkp->dev.parent = dev;
+ sdkp->dev.parent = get_device(dev);
sdkp->dev.class = &sd_disk_class;
dev_set_name(&sdkp->dev, "%s", dev_name(dev));
error = device_add(&sdkp->dev);
- if (error)
- goto out_free_index;
+ if (error) {
+ put_device(&sdkp->dev);
+ goto out;
+ }
- get_device(dev);
dev_set_drvdata(dev, sdkp);
gd->major = sd_major((index & 0xf0) >> 4);