Skip to contentSkip to conversation

clk: ti: Call of_node_get() before of_find_xxx() API

PATCH In review Liang He 2 participants 2 messages Sep 15, 2022 – Oct 1, 2022

Subsystems (2)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 clk: ti: Call of_node_get() before of_find_xxx() API

In ti_find_clock_provider(), we need to call of_node_get() for of_find_node_by_name() which will automatically call of_node_put() for the 'from' argument.

Fixes 51f661ef9a10 ("clk: ti: Add ti_find_clock_provider() to use clock-output-names")
---
 drivers/clk/ti/clk.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/ti/clk.c +1 -0
index 373e9438b57a..7c390cd67e1a 100644
@@ -147,6 +147,7 @@ static struct device_node *ti_find_clock_provider(struct device_node *from,
 		return np;
 
 	/* Fall back to using old node name base provider name */
+	of_node_get(from);
 	return of_find_node_by_name(from, name);
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Quoting Liang He (2022-09-14 20:11:21)

Quoted 15 lines

In ti_find_clock_provider(), we need to call of_node_get() for of_find_node_by_name() which will automatically call of_node_put() for the 'from' argument.

Fixes 51f661ef9a10 ("clk: ti: Add ti_find_clock_provider() to use clock-output-names")
---
 drivers/clk/ti/clk.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/ti/clk.c +0 -0
index 373e9438b57a..7c390cd67e1a 100644

drivers/clk/ti/clk.c static struct device_node *ti_find_clock_provider(struct device_node *from, · line 150

Quoted 4 lines
drivers/clk/ti/clk.c +1 -0
@@ -147,6 +147,7 @@ static struct device_node *ti_find_clock_provider(struct device_node *from,
                return np;
 
        /* Fall back to using old node name base provider name */
+       of_node_get(from);

It seems better to hold the reference from the earlier search.

drivers/clk/ti/clk.c static struct device_node *ti_find_clock_provider(struct device_node *from, · line 152

Quoted 2 lines
drivers/clk/ti/clk.c +0 -0
        return of_find_node_by_name(from, name);
 }

How about this?

----8<----

drivers/clk/ti/clk.c +3 -2
index ef2a445c63a3..a99279265e40 100644
@@ -139,11 +139,12 @@ static struct device_node *ti_find_clock_provider(struct device_node *from,
 			break;
 		}
 	}
-	of_node_put(from);
 	kfree(tmp);
 
-	if (found)
+	if (found) {
+		of_node_put(from);
 		return np;
+	}
 
 	/* Fall back to using old node name base provider name */
 	return of_find_node_by_name(from, name);