Skip to contentSkip to conversation

arm: omap2: control: Hold reference returned by of_get_child_by_name()

PATCH New Liang He 1 participant 1 message Jul 1, 2022

Subsystems (3)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 arm: omap2: control: Hold reference returned by of_get_child_by_name()

In omap_control_init(), there are two bugs in fact:

(1) we need to call of_node_put() for 'scm_conf' in fail path and when it is not used anymore.
(2) we should hold refernece returned by of_get_child_by_name() for 'clk_np' and then use it to call of_node_put() when it is not used anymore.

---
 arch/arm/mach-omap2/control.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/control.c +7 -2
index c514a9602269..4c23ccfcee5d 100644
@@ -793,7 +793,7 @@ int __init omap2_control_base_init(void)
  */
 int __init omap_control_init(void)
 {
-	struct device_node *np, *scm_conf;
+	struct device_node *np, *scm_conf, *clk_np;
 	const struct of_device_id *match;
 	const struct omap_prcm_init_data *data;
 	int ret;
@@ -817,13 +817,17 @@ int __init omap_control_init(void)
 				goto of_node_put;
 			}
 
-			if (of_get_child_by_name(scm_conf, "clocks")) {
+			clk_np = of_get_child_by_name(scm_conf, "clocks");
+			if (clk_np) {
+				of_node_put(clk_np);
 				ret = omap2_clk_provider_init(scm_conf,
 							      data->index,
 							      syscon, NULL);
 				if (ret)
 					goto of_node_put;
 			}
+
+			of_node_put(scm_conf);
 		} else {
 			/* No scm_conf found, direct access */
 			ret = omap2_clk_provider_init(np, data->index, NULL,
@@ -842,6 +846,7 @@ int __init omap_control_init(void)
 	return 0;
 
 of_node_put:
+	of_node_put(scm_conf);
 	of_node_put(np);
 	return ret;
 
Signature · 1 line
2.25.1