linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code
@ 2025-08-06 12:46 Qianfeng Rong
  2025-08-06 12:46 ` [PATCH v3 1/2] scsi: ipr: use vmalloc_array " Qianfeng Rong
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-06 12:46 UTC (permalink / raw)
  To: bvanassche, Brian King, James E.J. Bottomley, Martin K. Petersen,
	open list:SCSI SUBSYSTEM, open list
  Cc: Qianfeng Rong

Instead of using array_size, use a function that takes care of both the
multiplication and the overflow checks.

Compile-tested only.

Qianfeng Rong (2):
  scsi: ipr: Use vmalloc_array to simplify code
  scsi: scsi_debug: Use vcalloc to simplify code

 drivers/scsi/ipr.c        | 8 ++++----
 drivers/scsi/scsi_debug.c | 6 ++----
 2 files changed, 6 insertions(+), 8 deletions(-)

-- 
2.34.1


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

* [PATCH v3 1/2] scsi: ipr: use vmalloc_array to simplify code
  2025-08-06 12:46 [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
@ 2025-08-06 12:46 ` Qianfeng Rong
  2025-08-06 12:46 ` [PATCH v3 2/2] scsi: scsi_debug: use vcalloc " Qianfeng Rong
  2025-08-20  1:56 ` [PATCH v3 0/2] scsi: Use vmalloc_array and " Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-06 12:46 UTC (permalink / raw)
  To: bvanassche, Brian King, James E.J. Bottomley, Martin K. Petersen,
	open list:SCSI SUBSYSTEM, open list
  Cc: Qianfeng Rong

Use vmalloc_array() instead of vmalloc() to simplify the function
ipr_alloc_dump().

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/scsi/ipr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index d06b79f03538..4fb5654472d8 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -4281,11 +4281,11 @@ static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
 	}
 
 	if (ioa_cfg->sis64)
-		ioa_data = vmalloc(array_size(IPR_FMT3_MAX_NUM_DUMP_PAGES,
-					      sizeof(__be32 *)));
+		ioa_data = vmalloc_array(IPR_FMT3_MAX_NUM_DUMP_PAGES,
+					 sizeof(__be32 *));
 	else
-		ioa_data = vmalloc(array_size(IPR_FMT2_MAX_NUM_DUMP_PAGES,
-					      sizeof(__be32 *)));
+		ioa_data = vmalloc_array(IPR_FMT2_MAX_NUM_DUMP_PAGES,
+					 sizeof(__be32 *));
 
 	if (!ioa_data) {
 		ipr_err("Dump memory allocation failed\n");
-- 
2.34.1


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

* [PATCH v3 2/2] scsi: scsi_debug: use vcalloc to simplify code
  2025-08-06 12:46 [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
  2025-08-06 12:46 ` [PATCH v3 1/2] scsi: ipr: use vmalloc_array " Qianfeng Rong
@ 2025-08-06 12:46 ` Qianfeng Rong
  2025-08-06 15:20   ` Bart Van Assche
  2025-08-20  1:56 ` [PATCH v3 0/2] scsi: Use vmalloc_array and " Martin K. Petersen
  2 siblings, 1 reply; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-06 12:46 UTC (permalink / raw)
  To: bvanassche, James E.J. Bottomley, Martin K. Petersen,
	open list:SCSI SUBSYSTEM, open list
  Cc: Qianfeng Rong

Use vcalloc() instead of vmalloc() followed by bitmap_zero() to simplify
the function sdebug_add_store().

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/scsi/scsi_debug.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 353cb60e1abe..14e2d6e94dd2 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -8805,8 +8805,8 @@ static int sdebug_add_store(void)
 	/* Logical Block Provisioning */
 	if (scsi_debug_lbp()) {
 		map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1;
-		sip->map_storep = vmalloc(array_size(sizeof(long),
-						     BITS_TO_LONGS(map_size)));
+		sip->map_storep = vcalloc(BITS_TO_LONGS(map_size),
+					  sizeof(long));
 
 		pr_info("%lu provisioning blocks\n", map_size);
 
@@ -8815,8 +8815,6 @@ static int sdebug_add_store(void)
 			goto err;
 		}
 
-		bitmap_zero(sip->map_storep, map_size);
-
 		/* Map first 1KB for partition table */
 		if (sdebug_num_parts)
 			map_region(sip, 0, 2);
-- 
2.34.1


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

* Re: [PATCH v3 2/2] scsi: scsi_debug: use vcalloc to simplify code
  2025-08-06 12:46 ` [PATCH v3 2/2] scsi: scsi_debug: use vcalloc " Qianfeng Rong
@ 2025-08-06 15:20   ` Bart Van Assche
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2025-08-06 15:20 UTC (permalink / raw)
  To: Qianfeng Rong, James E.J. Bottomley, Martin K. Petersen,
	open list:SCSI SUBSYSTEM, open list

On 8/6/25 5:46 AM, Qianfeng Rong wrote:
> Use vcalloc() instead of vmalloc() followed by bitmap_zero() to simplify
> the function sdebug_add_store().
Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code
  2025-08-06 12:46 [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
  2025-08-06 12:46 ` [PATCH v3 1/2] scsi: ipr: use vmalloc_array " Qianfeng Rong
  2025-08-06 12:46 ` [PATCH v3 2/2] scsi: scsi_debug: use vcalloc " Qianfeng Rong
@ 2025-08-20  1:56 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2025-08-20  1:56 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: bvanassche, Brian King, James E.J. Bottomley, Martin K. Petersen,
	open list:SCSI SUBSYSTEM, open list


Qianfeng,

> Instead of using array_size, use a function that takes care of both
> the multiplication and the overflow checks.

Applied to 6.18/scsi-staging, thanks!

-- 
Martin K. Petersen

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

end of thread, other threads:[~2025-08-20  1:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 12:46 [PATCH v3 0/2] scsi: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
2025-08-06 12:46 ` [PATCH v3 1/2] scsi: ipr: use vmalloc_array " Qianfeng Rong
2025-08-06 12:46 ` [PATCH v3 2/2] scsi: scsi_debug: use vcalloc " Qianfeng Rong
2025-08-06 15:20   ` Bart Van Assche
2025-08-20  1:56 ` [PATCH v3 0/2] scsi: Use vmalloc_array and " 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;
as well as URLs for NNTP newsgroup(s).