Skip to content

Commit 7f53c55

Browse files
nehebalexandrebelloni
authored andcommitted
i3c: master: use kzalloc_flex
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> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260312001534.24423-1-rosenp@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent eaa1d09 commit 7f53c55

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

drivers/i3c/master.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,10 +2820,10 @@ struct i3c_generic_ibi_slot {
28202820
struct i3c_generic_ibi_pool {
28212821
spinlock_t lock;
28222822
unsigned int num_slots;
2823-
struct i3c_generic_ibi_slot *slots;
28242823
void *payload_buf;
28252824
struct list_head free_slots;
28262825
struct list_head pending;
2826+
struct i3c_generic_ibi_slot slots[] __counted_by(num_slots);
28272827
};
28282828

28292829
/**
@@ -2851,7 +2851,6 @@ void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool)
28512851
WARN_ON(nslots != pool->num_slots);
28522852

28532853
kfree(pool->payload_buf);
2854-
kfree(pool->slots);
28552854
kfree(pool);
28562855
}
28572856
EXPORT_SYMBOL_GPL(i3c_generic_ibi_free_pool);
@@ -2874,20 +2873,16 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
28742873
unsigned int i;
28752874
int ret;
28762875

2877-
pool = kzalloc_obj(*pool);
2876+
pool = kzalloc_flex(*pool, slots, req->num_slots);
28782877
if (!pool)
28792878
return ERR_PTR(-ENOMEM);
28802879

2880+
pool->num_slots = req->num_slots;
2881+
28812882
spin_lock_init(&pool->lock);
28822883
INIT_LIST_HEAD(&pool->free_slots);
28832884
INIT_LIST_HEAD(&pool->pending);
28842885

2885-
pool->slots = kzalloc_objs(*slot, req->num_slots);
2886-
if (!pool->slots) {
2887-
ret = -ENOMEM;
2888-
goto err_free_pool;
2889-
}
2890-
28912886
if (req->max_payload_len) {
28922887
pool->payload_buf = kcalloc(req->num_slots,
28932888
req->max_payload_len, GFP_KERNEL);
@@ -2906,7 +2901,6 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
29062901
(i * req->max_payload_len);
29072902

29082903
list_add_tail(&slot->node, &pool->free_slots);
2909-
pool->num_slots++;
29102904
}
29112905

29122906
return pool;

0 commit comments

Comments
 (0)