On Fri, 2023-07-21 at 13:14 +0300, Andy Shevchenko wrote: > On Fri, Jul 21, 2023 at 09:59:37AM +0200, Nuno Sá wrote: > > On Thu, 2023-07-20 at 23:53 +0300, Andy Shevchenko wrote: > > ... > > > > + struct attribute **attrs, **attr, *clk = NULL; > > > struct iio_dev_attr *p; > > > - struct attribute **attr, *clk = NULL; > > > > > > /* First count elements in any existing group */ > > > - if (indio_dev->info->attrs) { > > > - attr = indio_dev->info->attrs->attrs; > > > - while (*attr++ != NULL) > > > + attrs = indio_dev->info->attrs ? indio_dev->info->attrs->attrs : > > > NULL; > > > + if (attrs) { > > > + for (attr = attrs; *attr; attr++) > > > attrcount_orig++; > > > not really related with the change... maybe just mention it in the commit? > > Hmm... It's related to make krealloc_array() to work as expected. > Hmm, I think it's arguable :). while() -> for() it's not really needed unless I'm missing something. You could even initialize 'attrs' to NULL at declaration and keep the above diff minimum. That said, I actually prefer this style (even though some people don't like much the ternary operator). > > > } > > ... > > > > iio_dev_opaque->chan_attr_group.attrs = > > > - kcalloc(attrcount + 1, > > > - sizeof(iio_dev_opaque->chan_attr_group.attrs[0]), > > > - GFP_KERNEL); > > > + krealloc_array(attrs, attrcount + 1, sizeof(*attrs), > > > GFP_KERNEL); > > > if (iio_dev_opaque->chan_attr_group.attrs == NULL) { > > > > since you're here and you also already did some style cleanups above, maybe > > change it to 'if (!iio_dev_opaque->chan_attr_group.attrs)'? > > I don't think it's related (but you can tell that this check related to > the allocator, and since we touch it, we may touch this), if Jonathan > wants this, I definitely do. Fair enough... - Nuno Sá