drivers/i2c/i2c-atr.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation.
Add __counted_by to get extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/i2c/i2c-atr.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index f9fcb4793aaf..e6d2af659d81 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -49,8 +49,8 @@ struct i2c_atr_alias_pair {
* @shared: Indicates if this alias pool is shared by multiple channels
*
* @lock: Lock protecting @aliases and @use_mask
- * @aliases: Array of aliases, must hold exactly @size elements
* @use_mask: Mask of used aliases
+ * @aliases: Array of aliases, must hold exactly @size elements
*/
struct i2c_atr_alias_pool {
size_t size;
@@ -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);
}
--
2.53.0
Hello Rosen, +Cc Cosmin, Romain On Fri Mar 27, 2026 at 4:03 AM CET, Rosen Penev wrote: > Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation. > > Add __counted_by to get extra runtime analysis. > > Signed-off-by: Rosen Penev <rosenp@gmail.com> This is the second version of the previous patch, so the subject line should start with "[PATCH v2]". You may try using b4 to automate this, it takes over this and many other boring-but-useful details. Additionally I suspect b4 would have a more complete Cc list, including recent contributors to this driver like Cosmin Tanislav and Romain Gantois who might want to review this patch. I'm Cc-ing them this time. > --- Also a changelog would be nice after the '---' marker, to help reviewers, and a link to previous versions. It took a moment to me to realize I had already reviewed almost the exact same code. Other than than the patch looks good: Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On Fri, Mar 27, 2026 at 1:12 AM Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: > > Hello Rosen, > > +Cc Cosmin, Romain > > On Fri Mar 27, 2026 at 4:03 AM CET, Rosen Penev wrote: > > Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation. > > > > Add __counted_by to get extra runtime analysis. > > > > Signed-off-by: Rosen Penev <rosenp@gmail.com> > > This is the second version of the previous patch, so the subject line > should start with "[PATCH v2]". You may try using b4 to automate this, it > takes over this and many other boring-but-useful details. Didn't realize that. I searched for attr vs atr in Sent... > > Additionally I suspect b4 would have a more complete Cc list, including > recent contributors to this driver like Cosmin Tanislav and Romain Gantois > who might want to review this patch. I'm Cc-ing them this time. I use ./scripts/get_maintainer.pl --no-git-fallback as it was requested elsewhere. > > > --- > > Also a changelog would be nice after the '---' marker, to help reviewers, > and a link to previous versions. It took a moment to me to realize I had > already reviewed almost the exact same code. Will do. > > Other than than the patch looks good: > > Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > -- > Luca Ceresoli, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com
© 2016 - 2026 Red Hat, Inc.