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

From: Andy Shevchenko
Date: Mon Jul 24 2023 - 06:38:59 EST


On Sat, Jul 22, 2023 at 06:28:20PM +0100, Jonathan Cameron wrote:
> On Fri, 21 Jul 2023 20:00:17 +0300
> Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:

...

> > + krealloc_array(attrs, attrcount + 1, sizeof(*attrs), GFP_KERNEL);
>
>
> I'm a little lost, but isn't this realloc()ing attrs, which should be provided
> by drivers as constant if it is set to indio_dev->info->attrs->attrs?
>
> That seems unlikely to work correctly, but I may well have lost track of the
> flow and attrs points somewhere else at this point. I guess it might work
> as the realloc code will detect it can't resize that array.

Argh!

The attrs are defined without const. So, basically to prevent code like this
we have to make sure our local variables are defined as const.

I will drop this hunk from the next version, need to think if it makes sense
to refactor and if so, in which way.

--
With Best Regards,
Andy Shevchenko