Skip to contentSkip to conversation

clk: st: Hold reference returned by of_get_parent()

PATCH Applied Liang He 2 participants 2 messages Jun 28, 2022 – Aug 19, 2022 Common clk

v2 of 5 Applied Latest is v5 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 clk: st: Hold reference returned by of_get_parent()

We should hold the reference returned by of_get_parent() and use it to call of_node_put() for refcount balance.

Fixes 3efe64ef5186 ("clk: st: clkgen-fsyn: search reg within node or parent")
Fixes 810251b0d36a ("clk: st: clkgen-mux: search reg within node or parent")

---
changelog:

v2: replace 'tp' with 'parent_np', change title format to xx:yy:zz
v1: hold reference returned by of_get_parent()

v1-link: https://lore.kernel.org/all/[email protected]/

Patched files have been compiled test in 5.19rc2.

 drivers/clk/st/clkgen-fsyn.c | 5 ++++-
 drivers/clk/st/clkgen-mux.c  | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/clk/st/clkgen-fsyn.c +4 -1
index 582a22c04919..d820292a381d 100644
@@ -987,6 +987,7 @@ static void __init st_of_quadfs_setup(struct device_node *np,
 	const char *pll_name, *clk_parent_name;
 	void __iomem *reg;
 	spinlock_t *lock;
+	struct device_node *parent_np;
 
 	/*
 	 * First check for reg property within the node to keep backward
@@ -994,7 +995,9 @@ static void __init st_of_quadfs_setup(struct device_node *np,
 	 */
 	reg = of_iomap(np, 0);
 	if (!reg) {
-		reg = of_iomap(of_get_parent(np), 0);
+		parent_np = of_get_parent(np);
+		reg = of_iomap(parent_np, 0);
+		of_node_put(parent_np);
 		if (!reg) {
 			pr_err("%s: Failed to get base address\n", __func__);
 			return;
drivers/clk/st/clkgen-mux.c +4 -1
index ee39af7a0b72..596e939ad905 100644
@@ -56,6 +56,7 @@ static void __init st_of_clkgen_mux_setup(struct device_node *np,
 	void __iomem *reg;
 	const char **parents;
 	int num_parents = 0;
+	struct device_node *parent_np;
 
 	/*
 	 * First check for reg property within the node to keep backward
@@ -63,7 +64,9 @@ static void __init st_of_clkgen_mux_setup(struct device_node *np,
 	 */
 	reg = of_iomap(np, 0);
 	if (!reg) {
-		reg = of_iomap(of_get_parent(np), 0);
+		parent_np = of_get_parent(np);
+		reg = of_iomap(parent_np, 0);
+		of_node_put(parent_np);
 		if (!reg) {
 			pr_err("%s: Failed to get base address\n", __func__);
 			return;
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw

Quoting Liang He (2022-06-28 07:24:15)

Quoted 8 lines

We should hold the reference returned by of_get_parent() and use it to call of_node_put() for refcount balance.

Fixes 3efe64ef5186 ("clk: st: clkgen-fsyn: search reg within node or parent")
Fixes 810251b0d36a ("clk: st: clkgen-mux: search reg within node or parent")

---

Applied to clk-next