]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
IB/hfi1: kzalloc to kzalloc_flex
authorRosen Penev <rosenp@gmail.com>
Mon, 9 Mar 2026 21:50:17 +0000 (14:50 -0700)
committerLeon Romanovsky <leon@kernel.org>
Tue, 10 Mar 2026 18:04:09 +0000 (14:04 -0400)
Combine kzalloc and kcalloc with a flexible array member. Avoids having
to free separately.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260309215017.4753-1-rosenp@gmail.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hfi1/user_exp_rcv.c
drivers/infiniband/hw/hfi1/user_exp_rcv.h

index a916fe0118b10c9a8bdc542cb8cd0b28c7dd14ad..8b50a2ad792cb4daa79e0885b51859273f9f7cbc 100644 (file)
@@ -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 @@ unlock:
        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 @@ fail_unpin:
                unpin_rcv_pages(fd, tidbuf, NULL, 0, pinned, false);
 fail_release_mem:
        kfree(tidbuf->pages);
-       kfree(tidbuf->psets);
        kfree(tidbuf);
        kfree(tidlist);
        return ret;
index 055726f7c139f92edde74b391010972ecbfb3f78..b4a309a051f91fbc9952d144f7dc2a514757ed2a 100644 (file)
@@ -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 {