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