[PATCH v9 1/3] scsi: sd: Remove redundant printk after kmalloc failure

Abinash Singh posted 3 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v9 1/3] scsi: sd: Remove redundant printk after kmalloc failure
Posted by Abinash Singh 1 month, 1 week ago
The SCSI disk driver prints a warning when kmalloc() fails in
sd_revalidate_disk(). This is redundant because the page allocator
already reports failures unless __GFP_NOWARN is used. Keeping the
extra message only adds noise to the kernel log.

Remove the unnecessary sd_printk() call. Control flow is unchanged.

Fixes: e73aec824703 ("[SCSI] sd: make printing use a common prefix")
Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
 drivers/scsi/sd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 5b8668accf8e..aa9d944e27c5 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3712,11 +3712,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
 		goto out;
 
 	buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
-	if (!buffer) {
-		sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
-			  "allocation failure.\n");
+	if (!buffer)
 		goto out;
-	}
 
 	sd_spinup_disk(sdkp);
 
-- 
2.43.0
Re: [PATCH v9 1/3] scsi: sd: Remove redundant printk after kmalloc failure
Posted by Damien Le Moal 1 month, 1 week ago
On 8/25/25 3:02 AM, Abinash Singh wrote:
> The SCSI disk driver prints a warning when kmalloc() fails in
> sd_revalidate_disk(). This is redundant because the page allocator
> already reports failures unless __GFP_NOWARN is used. Keeping the
> extra message only adds noise to the kernel log.
> 
> Remove the unnecessary sd_printk() call. Control flow is unchanged.
> 
> Fixes: e73aec824703 ("[SCSI] sd: make printing use a common prefix")

I do not think this is necessary. Having the message is not a bug.

> Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>

As commented on patch 2, move this patch as patch 2 in the series as it does
not need backporting.

With that, feel free to add:

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

> ---
>  drivers/scsi/sd.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 5b8668accf8e..aa9d944e27c5 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -3712,11 +3712,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
>  		goto out;
>  
>  	buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
> -	if (!buffer) {
> -		sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
> -			  "allocation failure.\n");
> +	if (!buffer)
>  		goto out;

Nit: you can return 0 directly here. No need for the goto.

> -	}
>  
>  	sd_spinup_disk(sdkp);
>  


-- 
Damien Le Moal
Western Digital Research