diff options
| author | Rosen Penev <rosenp@gmail.com> | 2026-03-27 06:01:24 +0300 |
|---|---|---|
| committer | Leon Romanovsky <leon@kernel.org> | 2026-03-30 20:47:45 +0300 |
| commit | cef2842c922cb762e9cca7bb26b9ef06ef090b52 (patch) | |
| tree | beb9d6df74e06290c56ffd56fcf1599fe37b5e92 | |
| parent | dbeb256e8dd87233d891b170c0b32a6466467036 (diff) | |
| download | linux-cef2842c922cb762e9cca7bb26b9ef06ef090b52.tar.xz | |
RDMA/core: Use kzalloc_flex for GID table
Simplifies allocations by using a flexible array member in struct ib_gid_table.
Add __counted_by to get extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260327030124.8385-1-rosenp@gmail.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
| -rw-r--r-- | drivers/infiniband/core/cache.c | 14 |
1 files 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, |
