* [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return
@ 2019-07-09 18:00 Nishka Dasgupta
2019-07-12 6:50 ` Dmitry Torokhov
0 siblings, 1 reply; 2+ messages in thread
From: Nishka Dasgupta @ 2019-07-09 18:00 UTC (permalink / raw)
To: matthias.bgg, dmitry.torokhov, linux-input, linux-arm-kernel,
linux-mediatek
Cc: Nishka Dasgupta
Each iteration of for_each_child_of_node puts the previous
node, but in the case of a return from the middle of the loop, there is
no put, thus causing a memory leak. Hence add an of_node_put before the
return in three places.
Issue found with Coccinelle.
Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index 746ff06eaf8d..62391d6c7da6 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
keys->keys[index].irq = platform_get_irq(pdev, index);
- if (keys->keys[index].irq < 0)
+ if (keys->keys[index].irq < 0) {
+ of_node_put(child);
return keys->keys[index].irq;
+ }
error = of_property_read_u32(child,
"linux,keycodes", &keys->keys[index].keycode);
@@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
dev_err(keys->dev,
"failed to read key:%d linux,keycode property: %d\n",
index, error);
+ of_node_put(child);
return error;
}
@@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
keys->keys[index].wakeup = true;
error = mtk_pmic_key_setup(keys, &keys->keys[index]);
- if (error)
+ if (error) {
+ of_node_put(child);
return error;
+ }
index++;
}
--
2.19.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return
2019-07-09 18:00 [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return Nishka Dasgupta
@ 2019-07-12 6:50 ` Dmitry Torokhov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2019-07-12 6:50 UTC (permalink / raw)
To: Nishka Dasgupta
Cc: matthias.bgg, linux-mediatek, linux-arm-kernel, linux-input
On Tue, Jul 09, 2019 at 11:30:19PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous
> node, but in the case of a return from the middle of the loop, there is
> no put, thus causing a memory leak. Hence add an of_node_put before the
> return in three places.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Applied, thank you.
> ---
> drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 746ff06eaf8d..62391d6c7da6 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
> keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
>
> keys->keys[index].irq = platform_get_irq(pdev, index);
> - if (keys->keys[index].irq < 0)
> + if (keys->keys[index].irq < 0) {
> + of_node_put(child);
> return keys->keys[index].irq;
> + }
>
> error = of_property_read_u32(child,
> "linux,keycodes", &keys->keys[index].keycode);
> @@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
> dev_err(keys->dev,
> "failed to read key:%d linux,keycode property: %d\n",
> index, error);
> + of_node_put(child);
> return error;
> }
>
> @@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
> keys->keys[index].wakeup = true;
>
> error = mtk_pmic_key_setup(keys, &keys->keys[index]);
> - if (error)
> + if (error) {
> + of_node_put(child);
> return error;
> + }
>
> index++;
> }
> --
> 2.19.1
>
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-12 6:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-09 18:00 [PATCH] input: keyboard: mtk-pmic-keys: Add of_node_put() before return Nishka Dasgupta
2019-07-12 6:50 ` Dmitry Torokhov
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).