gpio: sim: fix an invalid __free() usage
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 20 Sep 2023 07:32:53 +0000 (09:32 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 22 Sep 2023 08:51:56 +0000 (10:51 +0200)
commit5cb9606a901a41f2ffe37fb8528bb6fbfb5d90e2
tree0a16a3a20feb058b05da0bf29b8752497464b12b
parentb547b5e52a0587e6b25ea520bf2f9e03d00cbcb6
gpio: sim: fix an invalid __free() usage

gpio_sim_make_line_names() returns NULL or ERR_PTR() so we must not use
__free(kfree) on the returned address. Split this function into two, one
that determines the size of the "gpio-line-names" array to allocate and
one that actually sets the names at correct offsets. The allocation and
assignment of the managed pointer happens in between.

Fixes: 3faf89f27aab ("gpio: sim: simplify code with cleanup helpers")
Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
Closes: https://lore.kernel.org/all/07c32bf1-6c1a-49d9-b97d-f0ae4a2b42ab@p183/
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-sim.c