Hi Rosen, all,

thanks for your patch. As stated, I think we shall make a change
to it, which exchanges 'num_pages' with more appropriate
'num_chunks' logic. Since I haven't received a response to my
first reply yet, I'll send an RFC patch right away. I'll
restrict it to linux-rdma list and other individuals on cc
in your patch.

Thanks,
Bernard.

On 29.03.2026 15:21, Bernard Metzler wrote:
On 27.03.2026 04:00, Rosen Penev wrote:
Simplifies allocations by using a flexible array member in this struct.

Add __counted_by to get extra runtime analysis.

Signed-off-by: Rosen Penev <[email protected]>
---
  drivers/infiniband/sw/siw/siw.h     |  2 +-
  drivers/infiniband/sw/siw/siw_mem.c | 12 +++---------
  2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw.h b/drivers/infiniband/sw/siw/siw.h
index f5fd71717b80..2b327a899a1c 100644
--- a/drivers/infiniband/sw/siw/siw.h
+++ b/drivers/infiniband/sw/siw/siw.h
@@ -119,9 +119,9 @@ struct siw_page_chunk {
  struct siw_umem {
      struct ib_umem *base_mem;
-    struct siw_page_chunk *page_chunk;
      int num_pages;

Shouldn't we replace 'num_pages' by a 'num_chunks' and change
memory allocation and release code accordingly?

      u64 fp_addr; /* First page base address */
+    struct siw_page_chunk page_chunk[] __counted_by(num_pages);
  };
  struct siw_pble {
diff --git a/drivers/infiniband/sw/siw/siw_mem.c 
b/drivers/infiniband/sw/siw/siw_mem.c
index 98c802b3ed72..08047fcf0df1 100644
--- a/drivers/infiniband/sw/siw/siw_mem.c
+++ b/drivers/infiniband/sw/siw/siw_mem.c
@@ -50,7 +50,6 @@ void siw_umem_release(struct siw_umem *umem)
          kfree(umem->page_chunk[i].plist);
          num_pages -= PAGES_PER_CHUNK;
      }
-    kfree(umem->page_chunk);
      kfree(umem);
  }
@@ -347,16 +346,12 @@ struct siw_umem *siw_umem_get(struct ib_device *base_dev, 
u64 start,
      num_pages = PAGE_ALIGN(start + len - first_page_va) >> PAGE_SHIFT;
      num_chunks = (num_pages >> CHUNK_SHIFT) + 1;
-    umem = kzalloc_obj(*umem);
+    umem = kzalloc_flex(*umem, page_chunk, num_chunks);
      if (!umem)
          return ERR_PTR(-ENOMEM);
-    umem->page_chunk =
-        kzalloc_objs(struct siw_page_chunk, num_chunks);
-    if (!umem->page_chunk) {
-        rv = -ENOMEM;
-        goto err_out;
-    }
+    umem->num_pages = num_pages;
+
      base_mem = ib_umem_get(base_dev, start, len, rights);
      if (IS_ERR(base_mem)) {
          rv = PTR_ERR(base_mem);
@@ -385,7 +380,6 @@ struct siw_umem *siw_umem_get(struct ib_device *base_dev, 
u64 start,
          umem->page_chunk[i].plist = plist;
          while (nents--) {
              *plist = sg_page_iter_page(&sg_iter);
-            umem->num_pages++;
              num_pages--;
              plist++;
              if (!__sg_page_iter_next(&sg_iter))



Reply via email to