mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init
@ 2022-06-07  3:00 Miaoqian Lin
  2022-06-07  5:01 ` Claudiu.Beznea
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-06-07  3:00 UTC (permalink / raw)
  To: Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Miaoqian Lin,
	Mihai Sain, Sudeep Holla, linux-arm-kernel, linux-kernel

of_find_node_by_path() returns a node pointer with refcount incremented,
we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes: 960ddf70cc11 ("drivers: soc: atmel: Avoid calling at91_soc_init on non AT91 SoCs")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- create new variable match to refactor the patch.

v1 Link: https://lore.kernel.org/r/20220605084035.27127-1-linmq006@gmail.com
---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/atmel/soc.c b/drivers/soc/atmel/soc.c
index b2d365ae0282..7152a38c657a 100644
--- a/drivers/soc/atmel/soc.c
+++ b/drivers/soc/atmel/soc.c
@@ -368,8 +368,11 @@ static const struct of_device_id at91_soc_allowed_list[] __initconst = {
 static int __init atmel_soc_device_init(void)
 {
 	struct device_node *np = of_find_node_by_path("/");
+	const struct of_device_id *match;
 
-	if (!of_match_node(at91_soc_allowed_list, np))
+	match = of_match_node(at91_soc_allowed_list, np);
+	of_node_put(np);
+	if (!match)
 		return 0;
 
 	at91_soc_init(socs);
-- 
2.25.1


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

* Re: [PATCH v2] drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init
  2022-06-07  3:00 [PATCH v2] drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init Miaoqian Lin
@ 2022-06-07  5:01 ` Claudiu.Beznea
  0 siblings, 0 replies; 2+ messages in thread
From: Claudiu.Beznea @ 2022-06-07  5:01 UTC (permalink / raw)
  To: linmq006, Nicolas.Ferre, alexandre.belloni, Mihai.Sain,
	sudeep.holla, linux-arm-kernel, linux-kernel

On 07.06.2022 06:00, Miaoqian Lin wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> of_find_node_by_path() returns a node pointer with refcount incremented,
> we should use of_node_put() on it when not need anymore.
> Add missing of_node_put() to avoid refcount leak.
> 
> Fixes: 960ddf70cc11 ("drivers: soc: atmel: Avoid calling at91_soc_init on non AT91 SoCs")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>


> ---
> changes in v2:
> - create new variable match to refactor the patch.
> 
> v1 Link: https://lore.kernel.org/r/20220605084035.27127-1-linmq006@gmail.com
> ---
>  drivers/soc/atmel/soc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/atmel/soc.c b/drivers/soc/atmel/soc.c
> index b2d365ae0282..7152a38c657a 100644
> --- a/drivers/soc/atmel/soc.c
> +++ b/drivers/soc/atmel/soc.c
> @@ -368,8 +368,11 @@ static const struct of_device_id at91_soc_allowed_list[] __initconst = {
>  static int __init atmel_soc_device_init(void)
>  {
>         struct device_node *np = of_find_node_by_path("/");
> +       const struct of_device_id *match;
> 
> -       if (!of_match_node(at91_soc_allowed_list, np))
> +       match = of_match_node(at91_soc_allowed_list, np);
> +       of_node_put(np);
> +       if (!match)
>                 return 0;
> 
>         at91_soc_init(socs);
> --
> 2.25.1
> 


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

end of thread, other threads:[~2022-06-07  5:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07  3:00 [PATCH v2] drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init Miaoqian Lin
2022-06-07  5:01 ` Claudiu.Beznea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®