Re: [PATCH v1 3/8] iio: core: Switch to krealloc_array()

Andy Shevchenko
2023-07-21T10:15:14Z

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.

> >         }

...

> >         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.

...

Thank you for the review!

--
With Best Regards,
Andy Shevchenko