Skip to contentSkip to conversation

drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init

PATCH Superseded Miaoqian Lin 3 participants 3 messages Jun 5, 2022 – Jun 6, 2022 Arm/Microchip (AT91) SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init

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")
---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/atmel/soc.c +4 -1
index b2d365ae0282..46dfa24c52fb 100644
@@ -369,10 +369,13 @@ static int __init atmel_soc_device_init(void)
 {
 	struct device_node *np = of_find_node_by_path("/");
 
-	if (!of_match_node(at91_soc_allowed_list, np))
+	if (!of_match_node(at91_soc_allowed_list, np)) {
+		of_node_put(np);
 		return 0;
+	}
 
 	at91_soc_init(socs);
+	of_node_put(np);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · Miaoqian Lin

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")
---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/atmel/soc.c +0 -0
index b2d365ae0282..46dfa24c52fb 100644

drivers/soc/atmel/soc.c static int __init atmel_soc_device_init(void) · line 371

Quoted 3 lines
drivers/soc/atmel/soc.c +0 -0
@@ -369,10 +369,13 @@ static int __init atmel_soc_device_init(void)
 {
        struct device_node *np = of_find_node_by_path("/");
 

What about having it like this:

	const struct of_device_id *of_id;

	of_id = of_match_node(at91_soc_allowed_list, np);
	of_node_put(np);
	if (!of_id)
		return 0;

And everything else the same?

Quoted 14 lines
drivers/soc/atmel/soc.c +4 -2
-       if (!of_match_node(at91_soc_allowed_list, np))
+       if (!of_match_node(at91_soc_allowed_list, np)) {
+               of_node_put(np);
                return 0;
+       }
 
        at91_soc_init(socs);
+       of_node_put(np);
 
        return 0;
 }
--

2.25.1

#2 lore raw
Quoted 23 lines · On Mon, Jun 06, 2022 at 09:00:52AM +0000, [email protected] wrote:
Quoted 17 lines · Miaoqian Lin

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")
---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/atmel/soc.c +0 -0
index b2d365ae0282..46dfa24c52fb 100644

drivers/soc/atmel/soc.c static int __init atmel_soc_device_init(void) · line 371

Quoted 3 lines
drivers/soc/atmel/soc.c +0 -0
@@ -369,10 +369,13 @@ static int __init atmel_soc_device_init(void)
 {
        struct device_node *np = of_find_node_by_path("/");
 

What about having it like this:

Quoted 4 lines
	const struct of_device_id *of_id;

	of_id = of_match_node(at91_soc_allowed_list, np);
	of_node_put(np);

+1, I was about to make similar suggestion in couple of other patches making similar changes.

Signature · 2 lines
Regards,
Sudeep