scsi: sd: fix error handling for sd_large_pool_create() call failure
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().
---
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
@@ -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
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 thedevice_add()call.
Quoted 7 lines
Fix this by mimicking the handling of
device_add_disk()failure, in callingdevice_unregister()andput_disk(). Thedevice_unregister()call will result inscsi_disk_release()being called, which unwinds many actions insd_probe().Fixes 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")Signed-off-by John Garry <[email protected]>
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@@ -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
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 thedevice_add()call.Fix this by mimicking the handling of
device_add_disk()failure, in callingdevice_unregister()andput_disk(). Thedevice_unregister()call will result inscsi_disk_release()being called, which unwinds many actions insd_probe().
Quoted 6 lines
Quoted 2 lines
Fixes 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")Signed-off-by John Garry <[email protected]>Xiuwei posted a series fixing this already:
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@@ -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; } }