From: Rosen Penev <rosenp@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: Saurav Kashyap <skashyap@marvell.com>,
Javed Hasan <jhasan@marvell.com>,
GR-QLogic-Storage-Upstream@marvell.com (maintainer:BROADCOM
BNX2FC 10 GIGABIT FCOE DRIVER),
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] scsi: bx2fc: use kzalloc_flex
Date: Thu, 19 Mar 2026 21:11:46 -0700 [thread overview]
Message-ID: <20260320041146.46873-1-rosenp@gmail.com> (raw)
Avoid calculating sizes manually.
Switch to flexible array member so that it works properly.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/scsi/bnx2fc/bnx2fc.h | 2 +-
drivers/scsi/bnx2fc/bnx2fc_io.c | 14 +++-----------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index 8c8968ec8cb4..30d8b563db0c 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -281,7 +281,7 @@ struct bnx2fc_cmd_mgr {
struct list_head *free_list;
spinlock_t *free_list_lock;
struct io_bdt **io_bdt_pool;
- struct bnx2fc_cmd **cmds;
+ struct bnx2fc_cmd *cmds[];
};
struct bnx2fc_rport {
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 9c7a541a4523..dd1c4b3232e1 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -213,8 +213,6 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)
struct bnx2fc_cmd_mgr *cmgr;
struct io_bdt *bdt_info;
struct bnx2fc_cmd *io_req;
- size_t len;
- u32 mem_size;
u16 xid;
int i;
int num_ios, num_pri_ios;
@@ -231,10 +229,8 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)
BNX2FC_MISC_DBG("min xid 0x%x, max xid 0x%x\n", min_xid, max_xid);
num_ios = max_xid - min_xid + 1;
- len = (num_ios * (sizeof(struct bnx2fc_cmd *)));
- len += sizeof(struct bnx2fc_cmd_mgr);
- cmgr = kzalloc(len, GFP_KERNEL);
+ cmgr = kzalloc_flex(*cmgr, cmds, num_ios);
if (!cmgr) {
printk(KERN_ERR PFX "failed to alloc cmgr\n");
return NULL;
@@ -255,8 +251,6 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)
goto mem_err;
}
- cmgr->cmds = (struct bnx2fc_cmd **)(cmgr + 1);
-
for (i = 0; i < arr_sz; i++) {
INIT_LIST_HEAD(&cmgr->free_list[i]);
spin_lock_init(&cmgr->free_list_lock[i]);
@@ -292,16 +286,14 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba)
}
/* Allocate pool of io_bdts - one for each bnx2fc_cmd */
- mem_size = num_ios * sizeof(struct io_bdt *);
- cmgr->io_bdt_pool = kzalloc(mem_size, GFP_KERNEL);
+ cmgr->io_bdt_pool = kzalloc_objs(struct io_bdt *, num_ios);
if (!cmgr->io_bdt_pool) {
printk(KERN_ERR PFX "failed to alloc io_bdt_pool\n");
goto mem_err;
}
- mem_size = sizeof(struct io_bdt);
for (i = 0; i < num_ios; i++) {
- cmgr->io_bdt_pool[i] = kmalloc(mem_size, GFP_KERNEL);
+ cmgr->io_bdt_pool[i] = kmalloc_obj(struct io_bdt);
if (!cmgr->io_bdt_pool[i]) {
printk(KERN_ERR PFX "failed to alloc "
"io_bdt_pool[%d]\n", i);
--
2.53.0
reply other threads:[~2026-03-20 4:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260320041146.46873-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=GR-QLogic-Storage-Upstream@marvell.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=jhasan@marvell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=skashyap@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox