gpio: Move freeing of GPIO hogs before numbing of the device
authorGeert Uytterhoeven <geert@linux-m68k.org>
Mon, 19 Dec 2016 17:29:23 +0000 (18:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jan 2017 19:18:00 +0000 (20:18 +0100)
commit86673e9331c929f43ff4c89bee056273ac2e3ed5
treed9b74af29256b499d8efb84b5a47618f4b655c42
parent0a28f5393689576a7667a7ef42cb79eafe16b019
gpio: Move freeing of GPIO hogs before numbing of the device

commit 5018ada69a04c8ac21d74bd682fceb8e42dc0f96 upstream.

When removing a gpiochip that uses GPIO hogging (e.g. by unloading the
chip's DT overlay), a warning is printed:

    gpio gpiochip8: REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED

This happens because gpiochip_free_hogs() is called after the gdev->chip
pointer is reset to NULL. Hence __gpiod_free() cannot determine the
chip in use, and cannot clear flags nor call the optional chip-specific
.free() callback.

Move the call to gpiochip_free_hogs() up to fix this.

Fixes: ff2b135922992756 ("gpio: make the gpiochip a real device")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpio/gpiolib.c