Skip to contentSkip to conversation

cpufreq: pmac64-cpufreq: Fix refcount leak on error paths

PATCH In review Miaoqian Lin 2 participants 2 messages Dec 12, 2025 – Dec 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: pmac64-cpufreq: Fix refcount leak on error paths

of_cpu_device_node_get obtain a reference to the device node which must be released with of_node_put().

Add missing of_node_put() on error paths to fix.

Found via static analysis and code review.

Fixes 760287ab90a3 ("cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes")
Fixes 4350147a816b ("[PATCH] ppc64: SMU based macs cpufreq support")
---
 drivers/cpufreq/pmac64-cpufreq.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/cpufreq/pmac64-cpufreq.c +9 -4
index 80897ec8f00e..0e0205b888ba 100644
@@ -356,8 +356,10 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
 		use_volts_smu = 1;
 	else if (of_machine_is_compatible("PowerMac11,2"))
 		use_volts_vdnap = 1;
-	else
-		return -ENODEV;
+	else {
+		rc = -ENODEV;
+		goto bail_noprops;
+	}
 
 	/* Check 970FX for now */
 	valp = of_get_property(cpunode, "cpu-version", NULL);
@@ -430,8 +432,11 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
 	 * supporting anything else.
 	 */
 	valp = of_get_property(cpunode, "clock-frequency", NULL);
-	if (!valp)
-		return -ENODEV;
+	if (!valp) {
+		rc = -ENODEV;
+		goto bail_noprops;
+	}
+
 	max_freq = (*valp)/1000;
 	g5_cpu_freqs[0].frequency = max_freq;
 	g5_cpu_freqs[1].frequency = max_freq/2;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 36 lines · Miaoqian Lin

of_cpu_device_node_get obtain a reference to the device node which must be released with of_node_put().

Add missing of_node_put() on error paths to fix.

Found via static analysis and code review.

Fixes 760287ab90a3 ("cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes")
Fixes 4350147a816b ("[PATCH] ppc64: SMU based macs cpufreq support")
---
 drivers/cpufreq/pmac64-cpufreq.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/cpufreq/pmac64-cpufreq.c +4 -2
index 80897ec8f00e..0e0205b888ba 100644
@@ -356,8 +356,10 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
 		use_volts_smu = 1;
 	else if (of_machine_is_compatible("PowerMac11,2"))
 		use_volts_vdnap = 1;
-	else
-		return -ENODEV;
+	else {
+		rc = -ENODEV;
+		goto bail_noprops;
+	}
 
 	/* Check 970FX for now */
 	valp = of_get_property(cpunode, "cpu-version", NULL);
@@ -430,8 +432,11 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
 	 * supporting anything else.
 	 */
 	valp = of_get_property(cpunode, "clock-frequency", NULL);

drivers/cpufreq/pmac64-cpufreq.c static int __init g5_neo2_cpufreq_init(struct device_node *cpunode) · line 442

Quoted 10 lines
drivers/cpufreq/pmac64-cpufreq.c +5 -2
-	if (!valp)
-		return -ENODEV;
+	if (!valp) {
+		rc = -ENODEV;
+		goto bail_noprops;
+	}
+
 	max_freq = (*valp)/1000;
 	g5_cpu_freqs[0].frequency = max_freq;
 	g5_cpu_freqs[1].frequency = max_freq/2;

I would rather handle this in the function that gets the reference of the node in the first place: g5_cpufreq_init().

Signature · 1 line
viresh