public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IB/hfi1: kzalloc to kzalloc_flex
@ 2026-03-08  3:19 Rosen Penev
  2026-03-08 15:59 ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-03-08  3:19 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>
---
 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


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

* Re: [PATCH] IB/hfi1: kzalloc to kzalloc_flex
  2026-03-08  3:19 [PATCH] IB/hfi1: kzalloc to kzalloc_flex Rosen Penev
@ 2026-03-08 15:59 ` Leon Romanovsky
  2026-03-08 20:09   ` Rosen Penev
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2026-03-08 15:59 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-rdma, Dennis Dalessandro, linux-hardening, gustavoars,
	Jason Gunthorpe, open list

On Sat, Mar 07, 2026 at 07:19:56PM -0800, Rosen Penev wrote:
> 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(-)

This patch needs to be rebased to latest rdma-next, due to the conflict
with already merged 94ff7c59cdfd ("RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion").

Thanks

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

* Re: [PATCH] IB/hfi1: kzalloc to kzalloc_flex
  2026-03-08 15:59 ` Leon Romanovsky
@ 2026-03-08 20:09   ` Rosen Penev
  2026-03-09  9:52     ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-03-08 20:09 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: linux-rdma, Dennis Dalessandro, linux-hardening, gustavoars,
	Jason Gunthorpe, open list

On Sun, Mar 8, 2026 at 9:00 AM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Sat, Mar 07, 2026 at 07:19:56PM -0800, Rosen Penev wrote:
> > 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(-)
>
> This patch needs to be rebased to latest rdma-next, due to the conflict
> with already merged 94ff7c59cdfd ("RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion").
https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/commit/?id=94ff7c59cdfd

Notice: this object is not reachable from any branch.

I'll take your word for it and rebase based on that.
>
> Thanks

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

* Re: [PATCH] IB/hfi1: kzalloc to kzalloc_flex
  2026-03-08 20:09   ` Rosen Penev
@ 2026-03-09  9:52     ` Leon Romanovsky
  0 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2026-03-09  9:52 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-rdma, Dennis Dalessandro, linux-hardening, gustavoars,
	Jason Gunthorpe, open list

On Sun, Mar 08, 2026 at 01:09:31PM -0700, Rosen Penev wrote:
> On Sun, Mar 8, 2026 at 9:00 AM Leon Romanovsky <leon@kernel.org> wrote:
> >
> > On Sat, Mar 07, 2026 at 07:19:56PM -0800, Rosen Penev wrote:
> > > 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(-)
> >
> > This patch needs to be rebased to latest rdma-next, due to the conflict
> > with already merged 94ff7c59cdfd ("RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversion").
> https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/commit/?id=94ff7c59cdfd
> 
> Notice: this object is not reachable from any branch.
> 
> I'll take your word for it and rebase based on that.

You looked at my private repo, while the patch exist in official RDMA
repository.

https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git/commit/?id=94ff7c59cdfd

Thanks

> >
> > Thanks

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

end of thread, other threads:[~2026-03-09  9:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-08  3:19 [PATCH] IB/hfi1: kzalloc to kzalloc_flex Rosen Penev
2026-03-08 15:59 ` Leon Romanovsky
2026-03-08 20:09   ` Rosen Penev
2026-03-09  9:52     ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox