gpioib: do not free unrequested descriptors
authorTimur Tabi <timur@codeaurora.org>
Thu, 29 Mar 2018 18:29:12 +0000 (13:29 -0500)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 26 Apr 2018 09:27:18 +0000 (11:27 +0200)
commitab3dbcf78f60f46d6a0ad63b1f4b690b7a427140
tree54dc4dd788f1bed7ed77eec19ecb7cfd08daf6b8
parentf241632fd087d3d9fbd5450f4d8c8604badd8348
gpioib: do not free unrequested descriptors

If the main loop in linehandle_create() encounters an error, it
unwinds completely by freeing all previously requested GPIO
descriptors.  However, if the error occurs in the beginning of
the loop before that GPIO is requested, then the exit code
attempts to free a null descriptor.  If extrachecks is enabled,
gpiod_free() triggers a WARN_ON.

Instead, keep a separate count of legitimate GPIOs so that only
those are freed.

Cc: stable@vger.kernel.org
Fixes: d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c