gpio: gpiolib-of.c: Add of_node_put() before break
diff mbox series

Message ID 20190706133422.3372-1-nishkadg.linux@gmail.com
State New
Headers show
Series
  • gpio: gpiolib-of.c: Add of_node_put() before break
Related show

Commit Message

Nishka Dasgupta July 6, 2019, 1:34 p.m. UTC
Each iteration of for_each_child_of_node puts the previous node, but in
the case of a break from the middle of the loop, there is no put, thus
causing a memory leak. Hence add an of_node_put before the break.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/gpio/gpiolib-of.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Bartosz Golaszewski July 8, 2019, 12:40 p.m. UTC | #1
sob., 6 lip 2019 o 15:34 Nishka Dasgupta <nishkadg.linux@gmail.com> napisaƂ(a):
>
> Each iteration of for_each_child_of_node puts the previous node, but in
> the case of a break from the middle of the loop, there is no put, thus
> causing a memory leak. Hence add an of_node_put before the break.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/gpio/gpiolib-of.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index aec7bd86ae7e..c9325efc1783 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -154,6 +154,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
>                                                         of_node_full_name(child));
>                                         *flags |= OF_GPIO_ACTIVE_LOW;
>                                 }
> +                               of_node_put(child);
>                                 break;
>                         }
>                 }
> --
> 2.19.1
>

Applied for fixes with a slightly changed commit message. Thanks!

Bartosz

Patch
diff mbox series

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index aec7bd86ae7e..c9325efc1783 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -154,6 +154,7 @@  static void of_gpio_flags_quirks(struct device_node *np,
 							of_node_full_name(child));
 					*flags |= OF_GPIO_ACTIVE_LOW;
 				}
+				of_node_put(child);
 				break;
 			}
 		}