* [PATCHv2] IB/hfi1: kzalloc to kzalloc_flex
@ 2026-03-09 21:50 Rosen Penev
2026-03-10 18:04 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-09 21:50 UTC (permalink / raw)
To: linux-rdma
Cc: Dennis Dalessandro, linux-hardening, gustavoars, Jason Gunthorpe,
Leon Romanovsky, open list
Combine kzalloc and kcalloc with a flexible array member. Avoids having
to free separately.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: rebase
drivers/infiniband/hw/hfi1/user_exp_rcv.c | 9 +--------
drivers/infiniband/hw/hfi1/user_exp_rcv.h | 2 +-
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
index a916fe0118b1..8b50a2ad792c 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_obj(*tidbuf);
+ tidbuf = kzalloc_flex(*tidbuf, psets, uctxt->expected_count);
if (!tidbuf)
return -ENOMEM;
@@ -265,11 +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 = kzalloc_objs(*tidbuf->psets, uctxt->expected_count);
- if (!tidbuf->psets) {
- ret = -ENOMEM;
- goto fail_release_mem;
- }
if (fd->use_mn) {
ret = mmu_interval_notifier_insert(
@@ -447,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;
@@ -470,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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCHv2] IB/hfi1: kzalloc to kzalloc_flex
2026-03-09 21:50 [PATCHv2] IB/hfi1: kzalloc to kzalloc_flex Rosen Penev
@ 2026-03-10 18:04 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-03-10 18:04 UTC (permalink / raw)
To: linux-rdma, Rosen Penev
Cc: Dennis Dalessandro, linux-hardening, gustavoars, Jason Gunthorpe,
linux-kernel
On Mon, 09 Mar 2026 14:50:17 -0700, Rosen Penev wrote:
> Combine kzalloc and kcalloc with a flexible array member. Avoids having
> to free separately.
Applied, thanks!
[1/1] IB/hfi1: kzalloc to kzalloc_flex
https://git.kernel.org/rdma/rdma/c/120ad1fd591402
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-10 18:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 21:50 [PATCHv2] IB/hfi1: kzalloc to kzalloc_flex Rosen Penev
2026-03-10 18:04 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox