Re: [PATCH v2] gpio: gpiolib: clear the array_info's memory space

From: Linus Walleij
Date: Mon May 15 2023 - 03:26:11 EST


> @@ -4359,6 +4359,8 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,

> * hardware number is different from its array index.
> */
> if (bitmap_full(array_info->get_mask, descs->ndescs)) {
> + /*clear descs->info*/
> + memset(array_info, 0, sizeof(struct gpio_array));
> array_info = NULL;

This is not the right solution.

The array_info points beyond descs and descs have be krealloc:ed
to fit the array info.

The right solution is not to fill that memory with zeroes, but to krealloc
back to the size that descs had before we did this resizing to begin
with.

Possibly the condition should be detected *before* we start to krealloc()
so we can avoid all the krealloc():ing.

If the actual issue cannot be fixed I think it is no better or worse to just
leave the code as it is, we are just zeroing some unused memory.

Yours,
Linus Walleij