Skip to content

Commit cef2842

Browse files
nehebrleon
authored andcommitted
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>
1 parent dbeb256 commit cef2842

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

drivers/infiniband/core/cache.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ struct ib_gid_table {
116116
/* rwlock protects data_vec[ix]->state and entry pointer.
117117
*/
118118
rwlock_t rwlock;
119-
struct ib_gid_table_entry **data_vec;
120119
/* bit field, each bit indicates the index of default GID */
121120
u32 default_gid_indices;
121+
struct ib_gid_table_entry *data_vec[] __counted_by(sz);
122122
};
123123

124124
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(
770770

771771
static struct ib_gid_table *alloc_gid_table(int sz)
772772
{
773-
struct ib_gid_table *table = kzalloc_obj(*table);
773+
struct ib_gid_table *table = kzalloc_flex(*table, data_vec, sz);
774774

775775
if (!table)
776776
return NULL;
777777

778-
table->data_vec = kzalloc_objs(*table->data_vec, sz);
779-
if (!table->data_vec)
780-
goto err_free_table;
778+
table->sz = sz;
781779

782780
mutex_init(&table->lock);
783-
784-
table->sz = sz;
785781
rwlock_init(&table->rwlock);
786782
return table;
787-
788-
err_free_table:
789-
kfree(table);
790-
return NULL;
791783
}
792784

793785
static void release_gid_table(struct ib_device *device,

0 commit comments

Comments
 (0)