Skip to contentSkip to conversation

drivers: soc: atmel: Fix refcount leak in atmel_soc_device_init

PATCH In review Miaoqian Lin 2 participants 2 messages Jun 7, 2022 Arm/Microchip (AT91) SoC support

lore
Share & tools
lore
#0 lore raw

PATCH v2 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")

---
changes in v2:
- create new variable match to refactor the patch.

v1 Link: https://lore.kernel.org/r/[email protected]

---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/atmel/soc.c +4 -1
index b2d365ae0282..7152a38c657a 100644
@@ -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);
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 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")
Quoted 29 lines

---
changes in v2:
- create new variable match to refactor the patch.

v1 Link: https://lore.kernel.org/r/[email protected]

---
 drivers/soc/atmel/soc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/soc/atmel/soc.c +4 -2
index b2d365ae0282..7152a38c657a 100644
@@ -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