Skip to contentSkip to conversation

Patch "thermal: cpu_cooling: free power table on error or when unregistering" has been added to the 4.2-stable tree

PATCH [email protected] 1 participant 1 message Oct 17, 2015

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

thermal: cpu_cooling: free power table on error or when unregistering

to the 4.2-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
thermal-cpu_cooling-free-power-table-on-error-or-when-unregistering.patch
and it can be found in the queue-4.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From eba4f88d5af84e0fcaa5d6eb4fe35a75c47203cb Mon Sep 17 00:00:00 2001

From: Javi Merino <[email protected]>
Date: Mon, 17 Aug 2015 19:21:43 +0100
Subject: thermal: cpu_cooling: free power table on error or when unregistering

From: Javi Merino <[email protected]>

commit eba4f88d5af84e0fcaa5d6eb4fe35a75c47203cb upstream.

The power table is not being freed on error from cpufreq_cooling register or when unregistering. Free it.

Fixes c36cf0717631 ("thermal: cpu_cooling: implement the power cooling device API")
Cc Zhang Rui <[email protected]>
Cc Eduardo Valentin <[email protected]>
---
 drivers/thermal/cpu_cooling.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/thermal/cpu_cooling.c +16 -5
@@ -272,7 +272,7 @@ static int build_dyn_power_table(struct
 	struct power_table *power_table;
 	struct dev_pm_opp *opp;
 	struct device *dev = NULL;
-	int num_opps = 0, cpu, i;
+	int num_opps = 0, cpu, i, ret = 0;
 	unsigned long freq;
 
 	for_each_cpu(cpu, &cpufreq_device->allowed_cpus) {
@@ -307,7 +307,8 @@ static int build_dyn_power_table(struct
 
 		if (i >= num_opps) {
 			rcu_read_unlock();
-			return -EAGAIN;
+			ret = -EAGAIN;
+			goto free_power_table;
 		}
 
 		freq_mhz = freq / 1000000;
@@ -329,14 +330,21 @@ static int build_dyn_power_table(struct
 
 	rcu_read_unlock();
 
-	if (i != num_opps)
-		return PTR_ERR(opp);
+	if (i != num_opps) {
+		ret = PTR_ERR(opp);
+		goto free_power_table;
+	}
 
 	cpufreq_device->cpu_dev = dev;
 	cpufreq_device->dyn_power_table = power_table;
 	cpufreq_device->dyn_power_table_entries = i;
 
 	return 0;
+
+free_power_table:
+	kfree(power_table);
+
+	return ret;
 }
 
 static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_device,
@@ -846,7 +854,7 @@ __cpufreq_cooling_register(struct device
 	ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
 	if (ret) {
 		cool_dev = ERR_PTR(ret);
-		goto free_table;
+		goto free_power_table;
 	}
 
 	snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
@@ -888,6 +896,8 @@ __cpufreq_cooling_register(struct device
 
 remove_idr:
 	release_idr(&cpufreq_idr, cpufreq_dev->id);
+free_power_table:
+	kfree(cpufreq_dev->dyn_power_table);
 free_table:
 	kfree(cpufreq_dev->freq_table);
 free_time_in_idle_timestamp:
@@ -1038,6 +1048,7 @@ void cpufreq_cooling_unregister(struct t
 
 	thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
 	release_idr(&cpufreq_idr, cpufreq_dev->id);
+	kfree(cpufreq_dev->dyn_power_table);
 	kfree(cpufreq_dev->time_in_idle_timestamp);
 	kfree(cpufreq_dev->time_in_idle);
 	kfree(cpufreq_dev->freq_table);

Patches currently in stable-queue which might be from [email protected] are

queue-4.2/thermal-cpu_cooling-don-t-call-kcalloc-under-rcu_read_lock.patch queue-4.2/thermal-cpu_cooling-free-power-table-on-error-or-when-unregistering.patch