From: Rosen Penev <rosenp@gmail.com>
To: linux-rdma@vger.kernel.org
Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
linux-hardening@vger.kernel.org, gustavoars@kernel.org,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] IB/hfi1: kzalloc to kzalloc_flex
Date: Sat, 7 Mar 2026 19:19:56 -0800 [thread overview]
Message-ID: <20260308031957.90900-1-rosenp@gmail.com> (raw)
Combine kzalloc and kcalloc with a flexible array member. Avoids having
to free separately.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/infiniband/hw/hfi1/user_exp_rcv.c | 10 +---------
drivers/infiniband/hw/hfi1/user_exp_rcv.h | 2 +-
2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
index 5b01070ed66f..2597d311fb1f 100644
--- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c
+++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
@@ -257,7 +257,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
if (tinfo->length == 0)
return -EINVAL;
- tidbuf = kzalloc(sizeof(*tidbuf), GFP_KERNEL);
+ tidbuf = kzalloc_flex(*tidbuf, psets, uctxt->expected_count);
if (!tidbuf)
return -ENOMEM;
@@ -265,12 +265,6 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
tidbuf->vaddr = tinfo->vaddr;
tidbuf->length = tinfo->length;
tidbuf->npages = num_user_pages(tidbuf->vaddr, tidbuf->length);
- tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets),
- GFP_KERNEL);
- if (!tidbuf->psets) {
- ret = -ENOMEM;
- goto fail_release_mem;
- }
if (fd->use_mn) {
ret = mmu_interval_notifier_insert(
@@ -448,7 +442,6 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
if (fd->use_mn)
mmu_interval_notifier_remove(&tidbuf->notifier);
kfree(tidbuf->pages);
- kfree(tidbuf->psets);
kfree(tidbuf);
kfree(tidlist);
return 0;
@@ -471,7 +464,6 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
unpin_rcv_pages(fd, tidbuf, NULL, 0, pinned, false);
fail_release_mem:
kfree(tidbuf->pages);
- kfree(tidbuf->psets);
kfree(tidbuf);
kfree(tidlist);
return ret;
diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.h b/drivers/infiniband/hw/hfi1/user_exp_rcv.h
index 055726f7c139..b4a309a051f9 100644
--- a/drivers/infiniband/hw/hfi1/user_exp_rcv.h
+++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.h
@@ -22,8 +22,8 @@ struct tid_user_buf {
unsigned long length;
unsigned int npages;
struct page **pages;
- struct tid_pageset *psets;
unsigned int n_psets;
+ struct tid_pageset psets[];
};
struct tid_rb_node {
--
2.53.0
next reply other threads:[~2026-03-08 3:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 3:19 Rosen Penev [this message]
2026-03-08 15:59 ` [PATCH] IB/hfi1: kzalloc to kzalloc_flex Leon Romanovsky
2026-03-08 20:09 ` Rosen Penev
2026-03-09 9:52 ` Leon Romanovsky
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=20260308031957.90900-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=gustavoars@kernel.org \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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