summaryrefslogtreecommitdiffstats
path: root/drivers/thermal
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-12-04 09:41:58 +0530
committerEduardo Valentin <edubezval@gmail.com>2014-12-08 12:08:57 -0400
commit730abe064b6f8860302b75a689ceed059c08e0b1 (patch)
treedd7c6b8c70300c12ba77d681e3af287c1d82f341 /drivers/thermal
parentc9ca319f0579cd51b07a666683157233c2cf720d (diff)
downloadop-kernel-dev-730abe064b6f8860302b75a689ceed059c08e0b1.zip
op-kernel-dev-730abe064b6f8860302b75a689ceed059c08e0b1.tar.gz
thermal: cpu_cooling: do error handling at the bottom in __cpufreq_cooling_register()
This makes life easy and bug free. And is scalable for future resource allocations. Acked-by: Javi Merino <javi.merino@arm.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/cpu_cooling.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 1dd4cc4..491d90a 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -448,8 +448,8 @@ __cpufreq_cooling_register(struct device_node *np,
ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
if (ret) {
- kfree(cpufreq_dev);
- return ERR_PTR(ret);
+ cool_dev = ERR_PTR(ret);
+ goto free_cdev;
}
snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
@@ -457,11 +457,9 @@ __cpufreq_cooling_register(struct device_node *np,
cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
&cpufreq_cooling_ops);
- if (IS_ERR(cool_dev)) {
- release_idr(&cpufreq_idr, cpufreq_dev->id);
- kfree(cpufreq_dev);
- return cool_dev;
- }
+ if (IS_ERR(cool_dev))
+ goto remove_idr;
+
cpufreq_dev->cool_dev = cool_dev;
mutex_lock(&cooling_cpufreq_lock);
@@ -476,6 +474,13 @@ __cpufreq_cooling_register(struct device_node *np,
mutex_unlock(&cooling_cpufreq_lock);
return cool_dev;
+
+remove_idr:
+ release_idr(&cpufreq_idr, cpufreq_dev->id);
+free_cdev:
+ kfree(cpufreq_dev);
+
+ return cool_dev;
}
/**
OpenPOWER on IntegriCloud