* [PATCH 1/6] gpio: fix memory and reference leaks in gpiochip_add error path
[not found] <1421079149-2236-1-git-send-email-johan@kernel.org>
@ 2015-01-12 16:12 ` Johan Hovold
2015-01-12 16:12 ` [PATCH 4/6] gpio: fix memory leak and sleep-while-atomic Johan Hovold
2015-01-12 16:12 ` [PATCH 5/6] gpio: fix sleep-while-atomic in gpiochip_remove Johan Hovold
2 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2015-01-12 16:12 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Johan Hovold, stable
Memory allocated and references taken by of_gpiochip_add and
acpi_gpiochip_add were never released on errors in gpiochip_add (e.g.
failure to find free gpio range).
Fixes: 391c970c0dd1 ("of/gpio: add default of_xlate function if device
has a node pointer")
Fixes: 664e3e5ac64c ("gpio / ACPI: register to ACPI events
automatically")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 487afe6f22fc..89c59f5f1924 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -277,6 +277,9 @@ int gpiochip_add(struct gpio_chip *chip)
spin_unlock_irqrestore(&gpio_lock, flags);
+ if (status)
+ goto fail;
+
#ifdef CONFIG_PINCTRL
INIT_LIST_HEAD(&chip->pin_ranges);
#endif
@@ -284,12 +287,12 @@ int gpiochip_add(struct gpio_chip *chip)
of_gpiochip_add(chip);
acpi_gpiochip_add(chip);
- if (status)
- goto fail;
-
status = gpiochip_export(chip);
- if (status)
+ if (status) {
+ acpi_gpiochip_remove(chip);
+ of_gpiochip_remove(chip);
goto fail;
+ }
pr_debug("%s: registered GPIOs %d to %d on device: %s\n", __func__,
chip->base, chip->base + chip->ngpio - 1,
--
2.0.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 4/6] gpio: fix memory leak and sleep-while-atomic
[not found] <1421079149-2236-1-git-send-email-johan@kernel.org>
2015-01-12 16:12 ` [PATCH 1/6] gpio: fix memory and reference leaks in gpiochip_add error path Johan Hovold
@ 2015-01-12 16:12 ` Johan Hovold
2015-01-12 16:12 ` [PATCH 5/6] gpio: fix sleep-while-atomic in gpiochip_remove Johan Hovold
2 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2015-01-12 16:12 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Johan Hovold, stable
Fix memory leak and sleep-while-atomic in gpiochip_remove.
The memory leak was introduced by afa82fab5e13 ("gpio / ACPI: Move event
handling registration to gpiolib irqchip helpers") that moved the
release of acpi interrupt resources to gpiochip_irqchip_remove, but by
then the resources are no longer accessible as the acpi_gpio_chip has
already been freed by acpi_gpiochip_remove.
Note that this also fixes a few potential sleep-while-atomics, which has
been around since 1425052097b5 ("gpio: add IRQ chip helpers in gpiolib")
when the call to gpiochip_irqchip_remove while holding a spinlock was
added (a couple of irq-domain paths can end up grabbing mutexes).
Fixes: afa82fab5e13 ("gpio / ACPI: Move event handling registration to
gpiolib irqchip helpers")
Fixes: 1425052097b5 ("gpio: add IRQ chip helpers in gpiolib")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4efb92ca3463..0f8173051edc 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -327,11 +327,12 @@ void gpiochip_remove(struct gpio_chip *chip)
unsigned long flags;
unsigned id;
+ gpiochip_irqchip_remove(chip);
+
acpi_gpiochip_remove(chip);
spin_lock_irqsave(&gpio_lock, flags);
- gpiochip_irqchip_remove(chip);
gpiochip_remove_pin_ranges(chip);
of_gpiochip_remove(chip);
--
2.0.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 5/6] gpio: fix sleep-while-atomic in gpiochip_remove
[not found] <1421079149-2236-1-git-send-email-johan@kernel.org>
2015-01-12 16:12 ` [PATCH 1/6] gpio: fix memory and reference leaks in gpiochip_add error path Johan Hovold
2015-01-12 16:12 ` [PATCH 4/6] gpio: fix memory leak and sleep-while-atomic Johan Hovold
@ 2015-01-12 16:12 ` Johan Hovold
2 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2015-01-12 16:12 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Johan Hovold, stable
Move direct and indirect calls to gpiochip_remove_pin_ranges outside of
spin lock as they can end up taking a mutex in pinctrl_remove_gpio_range.
Note that the pin ranges are already added outside of the lock.
Fixes: 9ef0d6f7628b ("gpiolib: call pin removal in chip removal function")
Fixes: f23f1516b675 ("gpiolib: provide provision to register pin ranges")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0f8173051edc..37f919dc2cb4 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -330,12 +330,10 @@ void gpiochip_remove(struct gpio_chip *chip)
gpiochip_irqchip_remove(chip);
acpi_gpiochip_remove(chip);
-
- spin_lock_irqsave(&gpio_lock, flags);
-
gpiochip_remove_pin_ranges(chip);
of_gpiochip_remove(chip);
+ spin_lock_irqsave(&gpio_lock, flags);
for (id = 0; id < chip->ngpio; id++) {
if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n");
--
2.0.5
^ permalink raw reply related [flat|nested] 3+ messages in thread