[PATCH] scsi: bnx2fc: Use kmalloc_array() for array allocations

From: Can Peng

Date: Tue Jun 23 2026 - 07:24:54 EST


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@xxxxxxxxxx>
---
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