linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] bus: mvebu-mbus: Add missing of_node_put()
@ 2022-06-17  2:55 Liang He
  0 siblings, 0 replies; only message in thread
From: Liang He @ 2022-06-17  2:55 UTC (permalink / raw)
  To: lpieralisi, pali, christophe.jaillet; +Cc: linux-kernel, windhl

In mvebu_mbus_dt_init(), of_find_matching_node_and_match() and
of_find_node_by_phandle() will both return node pointers with
refcount incremented. We should use of_node_put() in fail path
or when it is not used anymore.

Signed-off-by: Liang He <windhl@126.com>
---
 changelog:
 v3: (1) use goto-label patch style (2) fix v2 error reported by CJ 
 v2: (1) use real name (2) add of_node_put when not used anymore
 v1: add of_node_put in fail path

 drivers/bus/mvebu-mbus.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
index db612045616f..739f850cfcf1 100644
--- a/drivers/bus/mvebu-mbus.c
+++ b/drivers/bus/mvebu-mbus.c
@@ -1328,23 +1328,27 @@ int __init mvebu_mbus_dt_init(bool is_coherent)
 	prop = of_get_property(np, "controller", NULL);
 	if (!prop) {
 		pr_err("required 'controller' property missing\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_np_put;
 	}
 
 	controller = of_find_node_by_phandle(be32_to_cpup(prop));
 	if (!controller) {
 		pr_err("could not find an 'mbus-controller' node\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_np_put;
 	}
 
 	if (of_address_to_resource(controller, 0, &mbuswins_res)) {
 		pr_err("cannot get MBUS register address\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_controller_put;
 	}
 
 	if (of_address_to_resource(controller, 1, &sdramwins_res)) {
 		pr_err("cannot get SDRAM register address\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_controller_put;
 	}
 
 	/*
@@ -1375,9 +1379,16 @@ int __init mvebu_mbus_dt_init(bool is_coherent)
 				     resource_size(&mbusbridge_res),
 				     is_coherent);
 	if (ret)
-		return ret;
+		goto err_controller_put;
 
 	/* Setup statically declared windows in the DT */
-	return mbus_dt_setup(&mbus_state, np);
+	ret = mbus_dt_setup(&mbus_state, np);
+
+err_controller_put:
+	of_node_put(controller);
+err_np_put:
+	of_node_put(np);
+
+	return ret;
 }
 #endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-17  2:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17  2:55 [PATCH v3] bus: mvebu-mbus: Add missing of_node_put() Liang He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).