The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: fix error handling for sd_large_pool_create() call failure
@ 2026-07-07 10:55 John Garry
  2026-07-08  3:39 ` Damien Le Moal
  0 siblings, 1 reply; 3+ messages in thread
From: John Garry @ 2026-07-07 10:55 UTC (permalink / raw)
  To: James.Bottomley, martin.petersen
  Cc: p.raghav, sw.prabhu6, linux-scsi, linux-kernel, John Garry,
	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().

Fixes: 7179e626b76e ("scsi: sd: Enable sector size > PAGE_SIZE in SCSI sd driver")
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
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.

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 599e75f33334..d18693d390b2 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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;
 		}
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: sd: fix error handling for sd_large_pool_create() call failure
  2026-07-07 10:55 [PATCH] scsi: sd: fix error handling for sd_large_pool_create() call failure John Garry
@ 2026-07-08  3:39 ` Damien Le Moal
  2026-07-08  5:14   ` John Garry
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2026-07-08  3:39 UTC (permalink / raw)
  To: John Garry, James.Bottomley, martin.petersen
  Cc: p.raghav, sw.prabhu6, linux-scsi, linux-kernel, John Garry

On 7/7/26 19:55, John Garry wrote:
> 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")
> Signed-off-by: John Garry <john.g.garry@oracle.com>

Xiuwei posted a series fixing this already:

https://lore.kernel.org/all/20260707030333.22245-1-yangxiuwei@kylinos.cn/

> ---
> 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.
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 599e75f33334..d18693d390b2 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -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;
>  		}
>  	}
>  


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: sd: fix error handling for sd_large_pool_create() call failure
  2026-07-08  3:39 ` Damien Le Moal
@ 2026-07-08  5:14   ` John Garry
  0 siblings, 0 replies; 3+ messages in thread
From: John Garry @ 2026-07-08  5:14 UTC (permalink / raw)
  To: Damien Le Moal, John Garry, James.Bottomley, martin.petersen
  Cc: p.raghav, sw.prabhu6, linux-scsi, linux-kernel

On 08/07/2026 04:39, Damien Le Moal wrote:
> On 7/7/26 19:55, John Garry wrote:
>> 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")
>> Signed-off-by: John Garry <john.g.garry@oracle.com>
> 
> Xiuwei posted a series fixing this already:
> 
> https://lore.kernel.org/all/20260707030333.22245-1-yangxiuwei@kylinos.cn/

ah, I meant to check that series. cheers

> 
>> ---
>> 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.
>>
>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>> index 599e75f33334..d18693d390b2 100644
>> --- a/drivers/scsi/sd.c
>> +++ b/drivers/scsi/sd.c
>> @@ -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;
>>   		}
>>   	}
>>   
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-08  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 10:55 [PATCH] scsi: sd: fix error handling for sd_large_pool_create() call failure John Garry
2026-07-08  3:39 ` Damien Le Moal
2026-07-08  5:14   ` John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox