[PATCH] i3c: master: use kzalloc_flex

Rosen Penev posted 1 patch 3 weeks, 5 days ago
drivers/i3c/master.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
[PATCH] i3c: master: use kzalloc_flex
Posted by Rosen Penev 3 weeks, 5 days ago
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/i3c/master.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 9e6be49bebb2..b62cb3ee69c1 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2793,10 +2793,10 @@ struct i3c_generic_ibi_slot {
 struct i3c_generic_ibi_pool {
 	spinlock_t lock;
 	unsigned int num_slots;
-	struct i3c_generic_ibi_slot *slots;
 	void *payload_buf;
 	struct list_head free_slots;
 	struct list_head pending;
+	struct i3c_generic_ibi_slot slots[] __counted_by(num_slots);
 };
 
 /**
@@ -2824,7 +2824,6 @@ void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool)
 	WARN_ON(nslots != pool->num_slots);
 
 	kfree(pool->payload_buf);
-	kfree(pool->slots);
 	kfree(pool);
 }
 EXPORT_SYMBOL_GPL(i3c_generic_ibi_free_pool);
@@ -2847,20 +2846,16 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
 	unsigned int i;
 	int ret;
 
-	pool = kzalloc_obj(*pool);
+	pool = kzalloc_flex(*pool, slots, req->num_slots);
 	if (!pool)
 		return ERR_PTR(-ENOMEM);
 
+	pool->num_slots = req->num_slots;
+
 	spin_lock_init(&pool->lock);
 	INIT_LIST_HEAD(&pool->free_slots);
 	INIT_LIST_HEAD(&pool->pending);
 
-	pool->slots = kzalloc_objs(*slot, req->num_slots);
-	if (!pool->slots) {
-		ret = -ENOMEM;
-		goto err_free_pool;
-	}
-
 	if (req->max_payload_len) {
 		pool->payload_buf = kcalloc(req->num_slots,
 					    req->max_payload_len, GFP_KERNEL);
@@ -2879,7 +2874,6 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
 					  (i * req->max_payload_len);
 
 		list_add_tail(&slot->node, &pool->free_slots);
-		pool->num_slots++;
 	}
 
 	return pool;
-- 
2.53.0
Re: [PATCH] i3c: master: use kzalloc_flex
Posted by Alexandre Belloni 3 weeks, 4 days ago
On Wed, 11 Mar 2026 17:15:34 -0700, Rosen Penev wrote:
> i3c: master: use kzalloc_flex

Applied, thanks!

[1/1] i3c: master: use kzalloc_flex
      https://git.kernel.org/i3c/c/8ecd876fdaed

Best regards,
Re: [PATCH] i3c: master: use kzalloc_flex
Posted by Frank Li 3 weeks, 5 days ago
On Wed, Mar 11, 2026 at 05:15:34PM -0700, 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 <rosenp@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>