diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-03-29 22:59:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-03-29 22:59:49 -0400 |
commit | 89970a04d70c6c9e5e4492fd4096c0b5630a478c (patch) | |
tree | 21946302b9015bae501db21e1082160b4c055476 /drivers | |
parent | 806276b7f07a39a1cc3f38bb1ef5c573d4594a38 (diff) | |
parent | 3ea3217cf91804be6ed9b368ef4ac7911eb1dadc (diff) |
Merge branch 'for-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
Pull thermal management fixes from Zhang Rui:
- Fix a potential deadlock in cpu_cooling driver, which was introduced
in 4.11-rc1. (Matthew Wilcox)
- Fix the cpu_cooling and devfreq_cooling code to handle possible error
return value from OPP calls, together with three minor fixes in the
same patch series. (Viresh Kumar)
* 'for-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux:
thermal: cpu_cooling: Check OPP for errors
thermal: cpu_cooling: Replace dev_warn with dev_err
thermal: devfreq: Check OPP for errors
thermal: devfreq_cooling: Replace dev_warn with dev_err
thermal: devfreq: Simplify expression
thermal: Fix potential deadlock in cpu_cooling
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/thermal/cpu_cooling.c | 39 | ||||
-rw-r--r-- | drivers/thermal/devfreq_cooling.c | 14 |
2 files changed, 34 insertions, 19 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 91048eeca28b..69d0f430b2d1 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c | |||
@@ -107,8 +107,6 @@ struct cpufreq_cooling_device { | |||
107 | }; | 107 | }; |
108 | static DEFINE_IDA(cpufreq_ida); | 108 | static DEFINE_IDA(cpufreq_ida); |
109 | 109 | ||
110 | static unsigned int cpufreq_dev_count; | ||
111 | |||
112 | static DEFINE_MUTEX(cooling_list_lock); | 110 | static DEFINE_MUTEX(cooling_list_lock); |
113 | static LIST_HEAD(cpufreq_dev_list); | 111 | static LIST_HEAD(cpufreq_dev_list); |
114 | 112 | ||
@@ -395,13 +393,20 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, | |||
395 | 393 | ||
396 | opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, | 394 | opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, |
397 | true); | 395 | true); |
396 | if (IS_ERR(opp)) { | ||
397 | dev_warn_ratelimited(cpufreq_device->cpu_dev, | ||
398 | "Failed to find OPP for frequency %lu: %ld\n", | ||
399 | freq_hz, PTR_ERR(opp)); | ||
400 | return -EINVAL; | ||
401 | } | ||
402 | |||
398 | voltage = dev_pm_opp_get_voltage(opp); | 403 | voltage = dev_pm_opp_get_voltage(opp); |
399 | dev_pm_opp_put(opp); | 404 | dev_pm_opp_put(opp); |
400 | 405 | ||
401 | if (voltage == 0) { | 406 | if (voltage == 0) { |
402 | dev_warn_ratelimited(cpufreq_device->cpu_dev, | 407 | dev_err_ratelimited(cpufreq_device->cpu_dev, |
403 | "Failed to get voltage for frequency %lu: %ld\n", | 408 | "Failed to get voltage for frequency %lu\n", |
404 | freq_hz, IS_ERR(opp) ? PTR_ERR(opp) : 0); | 409 | freq_hz); |
405 | return -EINVAL; | 410 | return -EINVAL; |
406 | } | 411 | } |
407 | 412 | ||
@@ -693,9 +698,9 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, | |||
693 | 698 | ||
694 | *state = cpufreq_cooling_get_level(cpu, target_freq); | 699 | *state = cpufreq_cooling_get_level(cpu, target_freq); |
695 | if (*state == THERMAL_CSTATE_INVALID) { | 700 | if (*state == THERMAL_CSTATE_INVALID) { |
696 | dev_warn_ratelimited(&cdev->device, | 701 | dev_err_ratelimited(&cdev->device, |
697 | "Failed to convert %dKHz for cpu %d into a cdev state\n", | 702 | "Failed to convert %dKHz for cpu %d into a cdev state\n", |
698 | target_freq, cpu); | 703 | target_freq, cpu); |
699 | return -EINVAL; | 704 | return -EINVAL; |
700 | } | 705 | } |
701 | 706 | ||
@@ -771,6 +776,7 @@ __cpufreq_cooling_register(struct device_node *np, | |||
771 | unsigned int freq, i, num_cpus; | 776 | unsigned int freq, i, num_cpus; |
772 | int ret; | 777 | int ret; |
773 | struct thermal_cooling_device_ops *cooling_ops; | 778 | struct thermal_cooling_device_ops *cooling_ops; |
779 | bool first; | ||
774 | 780 | ||
775 | if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL)) | 781 | if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL)) |
776 | return ERR_PTR(-ENOMEM); | 782 | return ERR_PTR(-ENOMEM); |
@@ -874,13 +880,14 @@ __cpufreq_cooling_register(struct device_node *np, | |||
874 | cpufreq_dev->cool_dev = cool_dev; | 880 | cpufreq_dev->cool_dev = cool_dev; |
875 | 881 | ||
876 | mutex_lock(&cooling_list_lock); | 882 | mutex_lock(&cooling_list_lock); |
883 | /* Register the notifier for first cpufreq cooling device */ | ||
884 | first = list_empty(&cpufreq_dev_list); | ||
877 | list_add(&cpufreq_dev->node, &cpufreq_dev_list); | 885 | list_add(&cpufreq_dev->node, &cpufreq_dev_list); |
886 | mutex_unlock(&cooling_list_lock); | ||
878 | 887 | ||
879 | /* Register the notifier for first cpufreq cooling device */ | 888 | if (first) |
880 | if (!cpufreq_dev_count++) | ||
881 | cpufreq_register_notifier(&thermal_cpufreq_notifier_block, | 889 | cpufreq_register_notifier(&thermal_cpufreq_notifier_block, |
882 | CPUFREQ_POLICY_NOTIFIER); | 890 | CPUFREQ_POLICY_NOTIFIER); |
883 | mutex_unlock(&cooling_list_lock); | ||
884 | 891 | ||
885 | goto put_policy; | 892 | goto put_policy; |
886 | 893 | ||
@@ -1021,6 +1028,7 @@ EXPORT_SYMBOL(of_cpufreq_power_cooling_register); | |||
1021 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) | 1028 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) |
1022 | { | 1029 | { |
1023 | struct cpufreq_cooling_device *cpufreq_dev; | 1030 | struct cpufreq_cooling_device *cpufreq_dev; |
1031 | bool last; | ||
1024 | 1032 | ||
1025 | if (!cdev) | 1033 | if (!cdev) |
1026 | return; | 1034 | return; |
@@ -1028,14 +1036,15 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) | |||
1028 | cpufreq_dev = cdev->devdata; | 1036 | cpufreq_dev = cdev->devdata; |
1029 | 1037 | ||
1030 | mutex_lock(&cooling_list_lock); | 1038 | mutex_lock(&cooling_list_lock); |
1039 | list_del(&cpufreq_dev->node); | ||
1031 | /* Unregister the notifier for the last cpufreq cooling device */ | 1040 | /* Unregister the notifier for the last cpufreq cooling device */ |
1032 | if (!--cpufreq_dev_count) | 1041 | last = list_empty(&cpufreq_dev_list); |
1042 | mutex_unlock(&cooling_list_lock); | ||
1043 | |||
1044 | if (last) | ||
1033 | cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, | 1045 | cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, |
1034 | CPUFREQ_POLICY_NOTIFIER); | 1046 | CPUFREQ_POLICY_NOTIFIER); |
1035 | 1047 | ||
1036 | list_del(&cpufreq_dev->node); | ||
1037 | mutex_unlock(&cooling_list_lock); | ||
1038 | |||
1039 | thermal_cooling_device_unregister(cpufreq_dev->cool_dev); | 1048 | thermal_cooling_device_unregister(cpufreq_dev->cool_dev); |
1040 | ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); | 1049 | ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); |
1041 | kfree(cpufreq_dev->dyn_power_table); | 1050 | kfree(cpufreq_dev->dyn_power_table); |
diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 7743a78d4723..4bf4ad58cffd 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c | |||
@@ -186,16 +186,22 @@ get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) | |||
186 | return 0; | 186 | return 0; |
187 | 187 | ||
188 | opp = dev_pm_opp_find_freq_exact(dev, freq, true); | 188 | opp = dev_pm_opp_find_freq_exact(dev, freq, true); |
189 | if (IS_ERR(opp) && (PTR_ERR(opp) == -ERANGE)) | 189 | if (PTR_ERR(opp) == -ERANGE) |
190 | opp = dev_pm_opp_find_freq_exact(dev, freq, false); | 190 | opp = dev_pm_opp_find_freq_exact(dev, freq, false); |
191 | 191 | ||
192 | if (IS_ERR(opp)) { | ||
193 | dev_err_ratelimited(dev, "Failed to find OPP for frequency %lu: %ld\n", | ||
194 | freq, PTR_ERR(opp)); | ||
195 | return 0; | ||
196 | } | ||
197 | |||
192 | voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */ | 198 | voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */ |
193 | dev_pm_opp_put(opp); | 199 | dev_pm_opp_put(opp); |
194 | 200 | ||
195 | if (voltage == 0) { | 201 | if (voltage == 0) { |
196 | dev_warn_ratelimited(dev, | 202 | dev_err_ratelimited(dev, |
197 | "Failed to get voltage for frequency %lu: %ld\n", | 203 | "Failed to get voltage for frequency %lu\n", |
198 | freq, IS_ERR(opp) ? PTR_ERR(opp) : 0); | 204 | freq); |
199 | return 0; | 205 | return 0; |
200 | } | 206 | } |
201 | 207 | ||