All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: bnx2fc: Use kmalloc_array() for array allocations
@ 2026-06-23 11:24 Can Peng
  2026-06-23 11:41 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Can Peng @ 2026-06-23 11:24 UTC (permalink / raw)
  To: skashyap, jhasan, James.Bottomley, martin.petersen
  Cc: linux-scsi, linux-kernel, Can Peng

Documentation/process/deprecated.rst discourages open-coded arithmetic
in allocator arguments and recommends using the 2-factor allocator forms.

The unsolicited completion path allocates num_rq buffers of
BNX2FC_RQ_BUF_SZ bytes, and task_ctx_dma is an array of task_ctx_arr_sz
dma_addr_t entries. Use kmalloc_array() for both allocations.

Signed-off-by: Can Peng <pengcan@kylinos.cn>
---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index a5ecb87d5b2d..af6d27c3966e 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -655,8 +655,8 @@ static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
 		if (rq_data) {
 			buf = rq_data;
 		} else {
-			buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
-					      GFP_ATOMIC);
+			buf1 = buf = kmalloc_array(num_rq, BNX2FC_RQ_BUF_SZ,
+						   GFP_ATOMIC);
 
 			if (!buf1) {
 				BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
@@ -1904,8 +1904,8 @@ int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
 	/*
 	 * Allocate task_ctx_dma which is an array of dma addresses
 	 */
-	hba->task_ctx_dma = kmalloc((task_ctx_arr_sz *
-					sizeof(dma_addr_t)), GFP_KERNEL);
+	hba->task_ctx_dma = kmalloc_array(task_ctx_arr_sz,
+					  sizeof(dma_addr_t), GFP_KERNEL);
 	if (!hba->task_ctx_dma) {
 		printk(KERN_ERR PFX "unable to alloc context mapping array\n");
 		rc = -1;
-- 
2.53.0


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

end of thread, other threads:[~2026-06-23 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23 11:24 [PATCH] scsi: bnx2fc: Use kmalloc_array() for array allocations Can Peng
2026-06-23 11:41 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.