linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init
@ 2019-08-05 16:27 Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 2/4] pinctrl: samsung: Fix device node refcount leaks in S3C24xx " Krzysztof Kozlowski
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2019-08-05 16:27 UTC (permalink / raw)
  To: Tomasz Figa, Krzysztof Kozlowski, Sylwester Nawrocki,
	Linus Walleij, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-gpio, linux-kernel
  Cc: Chanwoo Choi, Marek Szyprowski, notify

In exynos_eint_wkup_init() the for_each_child_of_node() loop is used
with a break to find a matching child node.  Although each iteration of
for_each_child_of_node puts the previous node, but early exit from loop
misses it.  This leads to leak of device node.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/pinctrl/samsung/pinctrl-exynos.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
index ebc27b06718c..8d2c33bba13e 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
@@ -504,6 +504,7 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 				bank->nr_pins, &exynos_eint_irqd_ops, bank);
 		if (!bank->irq_domain) {
 			dev_err(dev, "wkup irq domain add failed\n");
+			of_node_put(wkup_np);
 			return -ENXIO;
 		}
 
@@ -518,8 +519,10 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 		weint_data = devm_kcalloc(dev,
 					  bank->nr_pins, sizeof(*weint_data),
 					  GFP_KERNEL);
-		if (!weint_data)
+		if (!weint_data) {
+			of_node_put(wkup_np);
 			return -ENOMEM;
+		}
 
 		for (idx = 0; idx < bank->nr_pins; ++idx) {
 			irq = irq_of_parse_and_map(bank->of_node, idx);
@@ -536,10 +539,13 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
 		}
 	}
 
-	if (!muxed_banks)
+	if (!muxed_banks) {
+		of_node_put(wkup_np);
 		return 0;
+	}
 
 	irq = irq_of_parse_and_map(wkup_np, 0);
+	of_node_put(wkup_np);
 	if (!irq) {
 		dev_err(dev, "irq number for muxed EINTs not found\n");
 		return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] pinctrl: samsung: Fix device node refcount leaks in S3C24xx wakeup controller init
  2019-08-05 16:27 [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Krzysztof Kozlowski
@ 2019-08-05 16:27 ` Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 3/4] pinctrl: samsung: Fix device node refcount leaks in S3C64xx " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2019-08-05 16:27 UTC (permalink / raw)
  To: Tomasz Figa, Krzysztof Kozlowski, Sylwester Nawrocki,
	Linus Walleij, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-gpio, linux-kernel
  Cc: Chanwoo Choi, Marek Szyprowski, notify

In s3c24xx_eint_init() the for_each_child_of_node() loop is used with a
break to find a matching child node.  Although each iteration of
for_each_child_of_node puts the previous node, but early exit from loop
misses it.  This leads to leak of device node.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/pinctrl/samsung/pinctrl-s3c24xx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
index 7e824e4d20f4..9bd0a3de101d 100644
--- a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
+++ b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
@@ -490,8 +490,10 @@ static int s3c24xx_eint_init(struct samsung_pinctrl_drv_data *d)
 		return -ENODEV;
 
 	eint_data = devm_kzalloc(dev, sizeof(*eint_data), GFP_KERNEL);
-	if (!eint_data)
+	if (!eint_data) {
+		of_node_put(eint_np);
 		return -ENOMEM;
+	}
 
 	eint_data->drvdata = d;
 
@@ -503,12 +505,14 @@ static int s3c24xx_eint_init(struct samsung_pinctrl_drv_data *d)
 		irq = irq_of_parse_and_map(eint_np, i);
 		if (!irq) {
 			dev_err(dev, "failed to get wakeup EINT IRQ %d\n", i);
+			of_node_put(eint_np);
 			return -ENXIO;
 		}
 
 		eint_data->parents[i] = irq;
 		irq_set_chained_handler_and_data(irq, handlers[i], eint_data);
 	}
+	of_node_put(eint_np);
 
 	bank = d->pin_banks;
 	for (i = 0; i < d->nr_banks; ++i, ++bank) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] pinctrl: samsung: Fix device node refcount leaks in S3C64xx wakeup controller init
  2019-08-05 16:27 [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 2/4] pinctrl: samsung: Fix device node refcount leaks in S3C24xx " Krzysztof Kozlowski
@ 2019-08-05 16:27 ` Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 4/4] pinctrl: samsung: Fix device node refcount leaks in init code Krzysztof Kozlowski
  2019-08-06 14:15 ` [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Linus Walleij
  3 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2019-08-05 16:27 UTC (permalink / raw)
  To: Tomasz Figa, Krzysztof Kozlowski, Sylwester Nawrocki,
	Linus Walleij, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-gpio, linux-kernel
  Cc: Chanwoo Choi, Marek Szyprowski, notify

In s3c64xx_eint_eint0_init() the for_each_child_of_node() loop is used
with a break to find a matching child node.  Although each iteration of
for_each_child_of_node puts the previous node, but early exit from loop
misses it.  This leads to leak of device node.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/pinctrl/samsung/pinctrl-s3c64xx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
index c399f0932af5..f97f8179f2b1 100644
--- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
+++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
@@ -704,8 +704,10 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 		return -ENODEV;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
-	if (!data)
+	if (!data) {
+		of_node_put(eint0_np);
 		return -ENOMEM;
+	}
 	data->drvdata = d;
 
 	for (i = 0; i < NUM_EINT0_IRQ; ++i) {
@@ -714,6 +716,7 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 		irq = irq_of_parse_and_map(eint0_np, i);
 		if (!irq) {
 			dev_err(dev, "failed to get wakeup EINT IRQ %d\n", i);
+			of_node_put(eint0_np);
 			return -ENXIO;
 		}
 
@@ -721,6 +724,7 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)
 						 s3c64xx_eint0_handlers[i],
 						 data);
 	}
+	of_node_put(eint0_np);
 
 	bank = d->pin_banks;
 	for (i = 0; i < d->nr_banks; ++i, ++bank) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] pinctrl: samsung: Fix device node refcount leaks in init code
  2019-08-05 16:27 [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 2/4] pinctrl: samsung: Fix device node refcount leaks in S3C24xx " Krzysztof Kozlowski
  2019-08-05 16:27 ` [PATCH 3/4] pinctrl: samsung: Fix device node refcount leaks in S3C64xx " Krzysztof Kozlowski
@ 2019-08-05 16:27 ` Krzysztof Kozlowski
  2019-08-06 14:15 ` [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Linus Walleij
  3 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2019-08-05 16:27 UTC (permalink / raw)
  To: Tomasz Figa, Krzysztof Kozlowski, Sylwester Nawrocki,
	Linus Walleij, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	linux-gpio, linux-kernel
  Cc: Chanwoo Choi, Marek Szyprowski, notify

Several functions use for_each_child_of_node() loop with a break to find
a matching child node.  Although each iteration of
for_each_child_of_node puts the previous node, but early exit from loop
misses it.  This leads to leak of device node.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index de0477bb469d..f26574ef234a 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -272,6 +272,7 @@ static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
 						&reserved_maps, num_maps);
 		if (ret < 0) {
 			samsung_dt_free_map(pctldev, *map, *num_maps);
+			of_node_put(np);
 			return ret;
 		}
 	}
@@ -785,8 +786,10 @@ static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 		if (!of_get_child_count(cfg_np)) {
 			ret = samsung_pinctrl_create_function(dev, drvdata,
 							cfg_np, func);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(cfg_np);
 				return ERR_PTR(ret);
+			}
 			if (ret > 0) {
 				++func;
 				++func_cnt;
@@ -797,8 +800,11 @@ static struct samsung_pmx_func *samsung_pinctrl_create_functions(
 		for_each_child_of_node(cfg_np, func_np) {
 			ret = samsung_pinctrl_create_function(dev, drvdata,
 						func_np, func);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(func_np);
+				of_node_put(cfg_np);
 				return ERR_PTR(ret);
+			}
 			if (ret > 0) {
 				++func;
 				++func_cnt;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init
  2019-08-05 16:27 [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2019-08-05 16:27 ` [PATCH 4/4] pinctrl: samsung: Fix device node refcount leaks in init code Krzysztof Kozlowski
@ 2019-08-06 14:15 ` Linus Walleij
  2019-08-06 14:25   ` Krzysztof Kozlowski
  3 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2019-08-06 14:15 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Tomasz Figa, Sylwester Nawrocki, Kukjin Kim, Linux ARM,
	linux-samsung-soc, open list:GPIO SUBSYSTEM, linux-kernel,
	Chanwoo Choi, Marek Szyprowski, notify

On Mon, Aug 5, 2019 at 6:27 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:

> In exynos_eint_wkup_init() the for_each_child_of_node() loop is used
> with a break to find a matching child node.  Although each iteration of
> for_each_child_of_node puts the previous node, but early exit from loop
> misses it.  This leads to leak of device node.
>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

I assume you're collecting these for a pull request to me
at some later point, all look good to me.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init
  2019-08-06 14:15 ` [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Linus Walleij
@ 2019-08-06 14:25   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2019-08-06 14:25 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Tomasz Figa, Sylwester Nawrocki, Kukjin Kim, Linux ARM,
	linux-samsung-soc, open list:GPIO SUBSYSTEM, linux-kernel,
	Chanwoo Choi, Marek Szyprowski, notify

On Tue, 6 Aug 2019 at 16:15, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Mon, Aug 5, 2019 at 6:27 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> > In exynos_eint_wkup_init() the for_each_child_of_node() loop is used
> > with a break to find a matching child node.  Although each iteration of
> > for_each_child_of_node puts the previous node, but early exit from loop
> > misses it.  This leads to leak of device node.
> >
> > Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
>
> I assume you're collecting these for a pull request to me
> at some later point, all look good to me.

Yes, I'll take these and one more patch from lists and send them to you.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-06 14:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-05 16:27 [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Krzysztof Kozlowski
2019-08-05 16:27 ` [PATCH 2/4] pinctrl: samsung: Fix device node refcount leaks in S3C24xx " Krzysztof Kozlowski
2019-08-05 16:27 ` [PATCH 3/4] pinctrl: samsung: Fix device node refcount leaks in S3C64xx " Krzysztof Kozlowski
2019-08-05 16:27 ` [PATCH 4/4] pinctrl: samsung: Fix device node refcount leaks in init code Krzysztof Kozlowski
2019-08-06 14:15 ` [PATCH 1/4] pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init Linus Walleij
2019-08-06 14:25   ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).