From: Rosen Penev <rosenp@gmail.com>
To: linux-i3c@lists.infradead.org
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
Frank Li <Frank.Li@nxp.com>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] i3c: master: use kzalloc_flex
Date: Wed, 11 Mar 2026 17:15:34 -0700 [thread overview]
Message-ID: <20260312001534.24423-1-rosenp@gmail.com> (raw)
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
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
next reply other threads:[~2026-03-12 0:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 0:15 Rosen Penev [this message]
2026-03-12 14:52 ` [PATCH] i3c: master: use kzalloc_flex Frank Li
2026-03-13 9:48 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312001534.24423-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-i3c@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox