Re: [PATCH 1/2] gpio: sim: fix an invalid __free() usage

From: Andy Shevchenko
Date: Sat Sep 16 2023 - 07:20:00 EST


On Fri, Sep 15, 2023 at 02:34:22PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> gpio_sim_make_line_names() returns NULL or ERR_PTR() so we must not use
> __free(kfree) on the returned address. Let's rework the function so that
> it returns the size of the gpio-line-names array or a negative error
> code on failure. This way we know that the string array will either stay
> NULL or be set to a correct, kcalloc()'ed address.

...

> + names = kcalloc(line_names_size, sizeof(*line_names), GFP_KERNEL);

sizeof(*line_names) is a bit unusual here. names is typed as double pointer,
while line_names as a tripple one.

--
With Best Regards,
Andy Shevchenko