diff mbox series

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

Message ID 20220701115116.233785-1-windhl@126.com
State New
Headers show
Series arm: omap2: control: Hold reference returned by of_get_child_by_name() | expand

Commit Message

Liang He July 1, 2022, 11:51 a.m. UTC
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.


Signed-off-by: Liang He <windhl@126.com>
---
 arch/arm/mach-omap2/control.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/arch/arm/mach-omap2/control.c b/arch/arm/mach-omap2/control.c
index c514a9602269..4c23ccfcee5d 100644
--- a/arch/arm/mach-omap2/control.c
+++ b/arch/arm/mach-omap2/control.c
@@ -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;