Skip to contentSkip to conversation

scsi: sd: free 'scsi_disk' device via put_device

PATCH Applied Ming Lei 4 participants 4 messages Sep 6, 2021 – Sep 14, 2021 SCSI

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 scsi: sd: free 'scsi_disk' device via put_device

Once the device is initialized via device_initialize(), it should be freed via put_device, so fix it. Meantime get the parent before adding device, the release handler can work as expected always.

---
 drivers/scsi/sd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/scsi/sd.c +5 -4
index cbd9999f93a6..a8039beb5a02 100644
@@ -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);
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Ming Lei

Once the device is initialized via device_initialize(), it should be freed via put_device, so fix it. Meantime get the parent before adding device, the release handler can work as expected always.

Since we are in the middle of the merge window this is probably not the best time to post patches. Anyway:

#3 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei

Once the device is initialized via device_initialize(), it should be freed via put_device, so fix it. Meantime get the parent before adding device, the release handler can work as expected always.

Applied to 5.15/scsi-fixes, thanks!

[1/1] scsi: sd: free 'scsi_disk' device via put_device

      https://git.kernel.org/mkp/scsi/c/265dfe8ebbab
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering