Skip to contentSkip to conversation

scsi: sd: fix error handling for sd_large_pool_create() call failure

PATCH In review John Garry 3 participants 3 messages Jul 7 – Jul 8 SCSI

lore
Share & tools
lore

John Garry

author
#0 lore raw

PATCH 1/1 scsi: sd: fix error handling for sd_large_pool_create() call failure

If the sd_probe() -> sd_large_pool_create() call fails, then we incorrectly unwind the probe actions.

Currently for the sd_large_pool_create() failure we do no undo the device_add() call.

Fix this by mimicking the handling of device_add_disk() failure, in calling device_unregister() and put_disk(). The device_unregister() call will result in scsi_disk_release() being called, which unwinds many actions in sd_probe().

Fixes 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")

---
I do wonder if it is simpler to always create this pool when we can support LBS. We only create a min of two elements in the pool, so hardly large.

drivers/scsi/sd.c +3 -1
index 599e75f33334..d18693d390b2 100644
@@ -4089,7 +4089,9 @@ static int sd_probe(struct scsi_device *sdp)
 	if (sdp->sector_size > PAGE_SIZE) {
 		if (sd_large_pool_create()) {
 			error = -ENOMEM;
-			goto out_free_index;
+			device_unregister(&sdkp->disk_dev);
+			put_disk(gd);
+			goto out;
 		}
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · John Garry

If the sd_probe() -> sd_large_pool_create() call fails, then we incorrectly unwind the probe actions.

Currently for the sd_large_pool_create() failure we do no undo the device_add() call.

Quoted 7 lines

Fix this by mimicking the handling of device_add_disk() failure, in calling device_unregister() and put_disk(). The device_unregister() call will result in scsi_disk_release() being called, which unwinds many actions in sd_probe().

Fixes 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")

Xiuwei posted a series fixing this already:

https://lore.kernel.org/all/[email protected]/

Quoted 20 lines

---
I do wonder if it is simpler to always create this pool when we can support LBS. We only create a min of two elements in the pool, so hardly large.

drivers/scsi/sd.c +3 -1
index 599e75f33334..d18693d390b2 100644
@@ -4089,7 +4089,9 @@ static int sd_probe(struct scsi_device *sdp)
 	if (sdp->sector_size > PAGE_SIZE) {
 		if (sd_large_pool_create()) {
 			error = -ENOMEM;
-			goto out_free_index;
+			device_unregister(&sdkp->disk_dev);
+			put_disk(gd);
+			goto out;
 		}
 	}
 
Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw
Quoted 12 lines · Damien Le Moal
Quoted 11 lines · John Garry

If the sd_probe() -> sd_large_pool_create() call fails, then we incorrectly unwind the probe actions.

Currently for the sd_large_pool_create() failure we do no undo the device_add() call.

Fix this by mimicking the handling of device_add_disk() failure, in calling device_unregister() and put_disk(). The device_unregister() call will result in scsi_disk_release() being called, which unwinds many actions in sd_probe().

Quoted 6 lines
Quoted 2 lines
Fixes 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")

Xiuwei posted a series fixing this already:

https://lore.kernel.org/all/[email protected]/

ah, I meant to check that series. cheers

Quoted 23 lines
Quoted 21 lines

---
I do wonder if it is simpler to always create this pool when we can support LBS. We only create a min of two elements in the pool, so hardly large.

drivers/scsi/sd.c +3 -1
index 599e75f33334..d18693d390b2 100644
@@ -4089,7 +4089,9 @@ static int sd_probe(struct scsi_device *sdp)
  	if (sdp->sector_size > PAGE_SIZE) {
  		if (sd_large_pool_create()) {
  			error = -ENOMEM;
-			goto out_free_index;
+			device_unregister(&sdkp->disk_dev);
+			put_disk(gd);
+			goto out;
  		}
  	}