public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: Prefer kmalloc_array over kmalloc involving dynamic size calculations
@ 2025-10-07  6:53 Bhanu Seshu Kumar Valluri
  2025-11-24 16:57 ` Bhanu Seshu Kumar Valluri
  0 siblings, 1 reply; 3+ messages in thread
From: Bhanu Seshu Kumar Valluri @ 2025-10-07  6:53 UTC (permalink / raw)
  To: Don Brace, James E . J . Bottomley, Martin K . Petersen
  Cc: storagedev, linux-scsi, linux-kernel, khalid,
	linux-kernel-mentees, skhan, david.hunter.linux, bhanuseshukumar,
	cassel

As a best practice use kmalloc_array to safely calculate dynamic object
sizes without overflow.

Acked-by: Don Brace <don.brace@microchip.com>
Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
---
 Note: The patch is tested for compilation.
 Change log:
 v1->v2:
  Updated commit message to refelect correct intention of the patch to 
  address James Bottomley review in v1.
  v1 Link : https://lore.kernel.org/all/20251001113935.52596-1-bhanuseshukumar@gmail.com/
 drivers/scsi/smartpqi/smartpqi_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 03c97e60d36f..19b0075eb256 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -8936,7 +8936,7 @@ static int pqi_host_alloc_mem(struct pqi_ctrl_info *ctrl_info,
 	if (sg_count == 0 || sg_count > PQI_HOST_MAX_SG_DESCRIPTORS)
 		goto out;
 
-	host_memory_descriptor->host_chunk_virt_address = kmalloc(sg_count * sizeof(void *), GFP_KERNEL);
+	host_memory_descriptor->host_chunk_virt_address = kmalloc_array(sg_count, sizeof(void *), GFP_KERNEL);
 	if (!host_memory_descriptor->host_chunk_virt_address)
 		goto out;
 
-- 
2.34.1


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

* Re: [PATCH v2] scsi: Prefer kmalloc_array over kmalloc involving dynamic size calculations
  2025-10-07  6:53 [PATCH v2] scsi: Prefer kmalloc_array over kmalloc involving dynamic size calculations Bhanu Seshu Kumar Valluri
@ 2025-11-24 16:57 ` Bhanu Seshu Kumar Valluri
  2025-11-29 20:26   ` Martin K. Petersen
  0 siblings, 1 reply; 3+ messages in thread
From: Bhanu Seshu Kumar Valluri @ 2025-11-24 16:57 UTC (permalink / raw)
  To: Don Brace, James E . J . Bottomley, Martin K . Petersen
  Cc: storagedev, linux-scsi, linux-kernel, khalid,
	linux-kernel-mentees, skhan, david.hunter.linux, cassel

On 07/10/25 12:23, Bhanu Seshu Kumar Valluri wrote:
> As a best practice use kmalloc_array to safely calculate dynamic object
> sizes without overflow.
> 
> Acked-by: Don Brace <don.brace@microchip.com>
> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
> ---
>  Note: The patch is tested for compilation.
>  Change log:
>  v1->v2:
>   Updated commit message to refelect correct intention of the patch to 
>   address James Bottomley review in v1.
>   v1 Link : https://lore.kernel.org/all/20251001113935.52596-1-bhanuseshukumar@gmail.com/
>  drivers/scsi/smartpqi/smartpqi_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
> index 03c97e60d36f..19b0075eb256 100644
> --- a/drivers/scsi/smartpqi/smartpqi_init.c
> +++ b/drivers/scsi/smartpqi/smartpqi_init.c
> @@ -8936,7 +8936,7 @@ static int pqi_host_alloc_mem(struct pqi_ctrl_info *ctrl_info,
>  	if (sg_count == 0 || sg_count > PQI_HOST_MAX_SG_DESCRIPTORS)
>  		goto out;
>  
> -	host_memory_descriptor->host_chunk_virt_address = kmalloc(sg_count * sizeof(void *), GFP_KERNEL);
> +	host_memory_descriptor->host_chunk_virt_address = kmalloc_array(sg_count, sizeof(void *), GFP_KERNEL);
>  	if (!host_memory_descriptor->host_chunk_virt_address)
>  		goto out;
>  

Hi,

I just wanted to check if you had a chance to review it or if any changes are needed from my side.

Regards,
Bhanu Seshu Kumar Valluri

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

* Re: [PATCH v2] scsi: Prefer kmalloc_array over kmalloc involving dynamic size calculations
  2025-11-24 16:57 ` Bhanu Seshu Kumar Valluri
@ 2025-11-29 20:26   ` Martin K. Petersen
  0 siblings, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2025-11-29 20:26 UTC (permalink / raw)
  To: Bhanu Seshu Kumar Valluri
  Cc: Don Brace, James E . J . Bottomley, Martin K . Petersen,
	storagedev, linux-scsi, linux-kernel, khalid,
	linux-kernel-mentees, skhan, david.hunter.linux, cassel


Bhanu,

> I just wanted to check if you had a chance to review it or if any
> changes are needed from my side.

This patch was merged last month.

-- 
Martin K. Petersen

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

end of thread, other threads:[~2025-11-29 20:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-07  6:53 [PATCH v2] scsi: Prefer kmalloc_array over kmalloc involving dynamic size calculations Bhanu Seshu Kumar Valluri
2025-11-24 16:57 ` Bhanu Seshu Kumar Valluri
2025-11-29 20:26   ` Martin K. Petersen

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