From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "Rosen Penev" <rosenp@gmail.com>, <linux-i2c@vger.kernel.org>
Cc: "Wolfram Sang" <wsa+renesas@sang-engineering.com>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.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: Fri, 13 Mar 2026 09:17:09 +0100 [thread overview]
Message-ID: <DH1I88QT17NI.1MZERF8Z4M6P5@bootlin.com> (raw)
In-Reply-To: <20260313002308.119343-1-rosenp@gmail.com>
Hello Rosen,
On Fri Mar 13, 2026 at 1:23 AM CET, 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.
Not sure what you mean by the last sentence, you are not moving the
assignment.
> --- 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);
Please reorder the parameters accordingly in the kdoc documentation above.
> @@ -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;
I'm not really sure about that, but I suspect kzalloc_flex() does set the
counter variable automatically if it's annotated using __counted_by. If
that's true, you can drop this line.
Otherwise LGTM.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-03-13 8:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 0:23 Rosen Penev
2026-03-13 8:17 ` Luca Ceresoli [this message]
2026-03-13 21:48 ` Rosen Penev
2026-03-30 8:50 ` Romain Gantois
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=DH1I88QT17NI.1MZERF8Z4M6P5@bootlin.com \
--to=luca.ceresoli@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=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
all inboxes | Powered by JetHome®