Commit 7f53c556 authored by Rosen Penev's avatar Rosen Penev Committed by Alexandre Belloni
Browse files

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: default avatarRosen Penev <rosenp@gmail.com>
Reviewed-by: default avatarFrank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260312001534.24423-1-rosenp@gmail.com


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent eaa1d092
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -2820,10 +2820,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);
};

/**
@@ -2851,7 +2851,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);
@@ -2874,20 +2873,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);
@@ -2906,7 +2901,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;