From: Romain Gantois <romain.gantois@bootlin.com>
To: linux-i2c@vger.kernel.org, Rosen Penev <rosenp@gmail.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] i2c: atr: use kzalloc_flex
Date: Mon, 30 Mar 2026 10:50:30 +0200 [thread overview]
Message-ID: <10827295.nUPlyArG6x@fw-rgant> (raw)
In-Reply-To: <20260313002308.119343-1-rosenp@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2265 bytes --]
Hello Rosen,
On Friday, 13 March 2026 01:23:08 CEST Rosen Penev wrote:
> Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation.
>
> Add __counted_by to get extra runtime analysis. Move counting variable
> assignment immediately after allocation as required by __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>
> drivers/i2c/i2c-atr.c | 15 +++------------
> 1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
> index f9fcb4793aaf..b0aedcf0bf71 100644
> --- a/drivers/i2c/i2c-atr.c
> +++ b/drivers/i2c/i2c-atr.c
> @@ -58,8 +58,8 @@ struct i2c_atr_alias_pool {
>
> /* Protects aliases and use_mask */
> spinlock_t lock;
>
> - u16 *aliases;
>
> unsigned long *use_mask;
>
> + u16 aliases[] __counted_by(size);
>
> };
>
> /**
>
> @@ -137,22 +137,16 @@ static struct i2c_atr_alias_pool
> *i2c_atr_alloc_alias_pool(size_t num_aliases, b struct i2c_atr_alias_pool
> *alias_pool;
>
> int ret;
>
> - alias_pool = kzalloc_obj(*alias_pool);
> + alias_pool = kzalloc_flex(*alias_pool, aliases, num_aliases);
>
> if (!alias_pool)
>
> return ERR_PTR(-ENOMEM);
>
> alias_pool->size = num_aliases;
>
> - alias_pool->aliases = kcalloc(num_aliases, sizeof(*alias_pool->aliases),
> GFP_KERNEL); - if (!alias_pool->aliases) {
> - ret = -ENOMEM;
> - goto err_free_alias_pool;
> - }
> -
>
> alias_pool->use_mask = bitmap_zalloc(num_aliases, GFP_KERNEL);
> if (!alias_pool->use_mask) {
>
> ret = -ENOMEM;
>
> - goto err_free_aliases;
> + goto err_free_alias_pool;
>
> }
>
> alias_pool->shared = shared;
>
> @@ -161,8 +155,6 @@ static struct i2c_atr_alias_pool
> *i2c_atr_alloc_alias_pool(size_t num_aliases, b
>
> return alias_pool;
>
> -err_free_aliases:
> - kfree(alias_pool->aliases);
>
> err_free_alias_pool:
> kfree(alias_pool);
> return ERR_PTR(ret);
>
> @@ -171,7 +163,6 @@ static struct i2c_atr_alias_pool
> *i2c_atr_alloc_alias_pool(size_t num_aliases, b static void
> i2c_atr_free_alias_pool(struct i2c_atr_alias_pool *alias_pool) {
>
> bitmap_free(alias_pool->use_mask);
>
> - kfree(alias_pool->aliases);
>
> kfree(alias_pool);
>
> }
Reviewed-by: Romain Gantois <romain.gantois@bootlin.com>
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-03-30 8:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 0:23 [PATCH] i2c: atr: use kzalloc_flex Rosen Penev
2026-03-13 8:17 ` Luca Ceresoli
2026-03-13 21:48 ` Rosen Penev
2026-03-30 8:50 ` Romain Gantois [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-03-27 3:03 Rosen Penev
2026-03-27 8:12 ` Luca Ceresoli
2026-03-27 18:35 ` Rosen Penev
2026-04-09 16:29 ` Andi Shyti
2026-04-09 16:37 ` Rosen Penev
2026-04-09 23:22 ` Andi Shyti
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=10827295.nUPlyArG6x@fw-rgant \
--to=romain.gantois@bootlin.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=rosenp@gmail.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=wsa+renesas@sang-engineering.com \
/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