* [PATCH] RDMA/core: use kzalloc_flex
@ 2026-03-27 3:01 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-03-27 3:01 UTC (permalink / raw)
To: linux-rdma
Cc: Jason Gunthorpe, Leon Romanovsky, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Simplifies allocations by using a flexible array member in this struct.
Add __counted_by to get extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/infiniband/core/cache.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index ee4a2bc68fb2..896486fa6185 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -116,9 +116,9 @@ struct ib_gid_table {
/* rwlock protects data_vec[ix]->state and entry pointer.
*/
rwlock_t rwlock;
- struct ib_gid_table_entry **data_vec;
/* bit field, each bit indicates the index of default GID */
u32 default_gid_indices;
+ struct ib_gid_table_entry *data_vec[] __counted_by(sz);
};
static void dispatch_gid_change_event(struct ib_device *ib_dev, u32 port)
@@ -770,24 +770,16 @@ const struct ib_gid_attr *rdma_find_gid_by_filter(
static struct ib_gid_table *alloc_gid_table(int sz)
{
- struct ib_gid_table *table = kzalloc_obj(*table);
+ struct ib_gid_table *table = kzalloc_flex(*table, data_vec, sz);
if (!table)
return NULL;
- table->data_vec = kzalloc_objs(*table->data_vec, sz);
- if (!table->data_vec)
- goto err_free_table;
+ table->sz = sz;
mutex_init(&table->lock);
-
- table->sz = sz;
rwlock_init(&table->rwlock);
return table;
-
-err_free_table:
- kfree(table);
- return NULL;
}
static void release_gid_table(struct ib_device *device,
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-27 3:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 3:01 [PATCH] RDMA/core: use kzalloc_flex Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox