gpio: don't free unallocated ida on gpiochip_add_data_with_key() error path
authorVladimir Zapolskiy <vz@mleia.com>
Fri, 2 Nov 2018 13:39:43 +0000 (15:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Dec 2018 08:42:50 +0000 (09:42 +0100)
commit6a5f25e30045bb2c3622136807d76be3bd4fb0ba
tree9ad41897a0a00ba0cb98c3353d5ac76b5eba86e0
parent7c9f55c5a58a8a7131e1f5a82a7f85bf06c62a63
gpio: don't free unallocated ida on gpiochip_add_data_with_key() error path

commit a05a14049999598a3bb6fab12db6b768a0215522 upstream.

The change corrects the error path in gpiochip_add_data_with_key()
by avoiding to call ida_simple_remove(), if ida_simple_get() returns
an error.

Note that ida_simple_remove()/ida_free() throws a BUG(), if id argument
is negative, it allows to easily check the correctness of the fix by
fuzzing the return value from ida_simple_get().

Fixes: ff2b13592299 ("gpio: make the gpiochip a real device")
Cc: stable@vger.kernel.org # v4.6+
Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpio/gpiolib.c