From: Johan Hovold <johan@kernel.org>
Date: Mon, 12 Jan 2015 16:12:29 +0000 (+0100)
Subject: gpio: unregister gpiochip device before removing it
X-Git-Tag: firefly_0821_release~3679^2~448
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=864c329b21a1914105a9e591b49def3f30184b65;p=firefly-linux-kernel-4.4.55.git

gpio: unregister gpiochip device before removing it

commit 01cca93a9491ed95992523ff7e79dd9bfcdea8e0 upstream.

Unregister gpiochip device (used to export information through sysfs)
before removing it internally. This way removal will reverse addition.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index ca1cb2d756c2..df4780810e83 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1265,6 +1265,8 @@ int gpiochip_remove(struct gpio_chip *chip)
 	int		status = 0;
 	unsigned	id;
 
+	gpiochip_unexport(chip);
+
 	spin_lock_irqsave(&gpio_lock, flags);
 
 	gpiochip_remove_pin_ranges(chip);
@@ -1285,9 +1287,6 @@ int gpiochip_remove(struct gpio_chip *chip)
 
 	spin_unlock_irqrestore(&gpio_lock, flags);
 
-	if (status == 0)
-		gpiochip_unexport(chip);
-
 	return status;
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);