Skip to content

Commit 89970a0

Browse files
committed
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
2 parents 806276b + 3ea3217 commit 89970a0

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

drivers/thermal/cpu_cooling.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ struct cpufreq_cooling_device {
107107
};
108108
static DEFINE_IDA(cpufreq_ida);
109109

110-
static unsigned int cpufreq_dev_count;
111-
112110
static DEFINE_MUTEX(cooling_list_lock);
113111
static LIST_HEAD(cpufreq_dev_list);
114112

@@ -395,13 +393,20 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device,
395393

396394
opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz,
397395
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+
398403
voltage = dev_pm_opp_get_voltage(opp);
399404
dev_pm_opp_put(opp);
400405

401406
if (voltage == 0) {
402-
dev_warn_ratelimited(cpufreq_device->cpu_dev,
403-
"Failed to get voltage for frequency %lu: %ld\n",
404-
freq_hz, IS_ERR(opp) ? PTR_ERR(opp) : 0);
407+
dev_err_ratelimited(cpufreq_device->cpu_dev,
408+
"Failed to get voltage for frequency %lu\n",
409+
freq_hz);
405410
return -EINVAL;
406411
}
407412

@@ -693,9 +698,9 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
693698

694699
*state = cpufreq_cooling_get_level(cpu, target_freq);
695700
if (*state == THERMAL_CSTATE_INVALID) {
696-
dev_warn_ratelimited(&cdev->device,
697-
"Failed to convert %dKHz for cpu %d into a cdev state\n",
698-
target_freq, cpu);
701+
dev_err_ratelimited(&cdev->device,
702+
"Failed to convert %dKHz for cpu %d into a cdev state\n",
703+
target_freq, cpu);
699704
return -EINVAL;
700705
}
701706

@@ -771,6 +776,7 @@ __cpufreq_cooling_register(struct device_node *np,
771776
unsigned int freq, i, num_cpus;
772777
int ret;
773778
struct thermal_cooling_device_ops *cooling_ops;
779+
bool first;
774780

775781
if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
776782
return ERR_PTR(-ENOMEM);
@@ -874,13 +880,14 @@ __cpufreq_cooling_register(struct device_node *np,
874880
cpufreq_dev->cool_dev = cool_dev;
875881

876882
mutex_lock(&cooling_list_lock);
883+
/* Register the notifier for first cpufreq cooling device */
884+
first = list_empty(&cpufreq_dev_list);
877885
list_add(&cpufreq_dev->node, &cpufreq_dev_list);
886+
mutex_unlock(&cooling_list_lock);
878887

879-
/* Register the notifier for first cpufreq cooling device */
880-
if (!cpufreq_dev_count++)
888+
if (first)
881889
cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
882890
CPUFREQ_POLICY_NOTIFIER);
883-
mutex_unlock(&cooling_list_lock);
884891

885892
goto put_policy;
886893

@@ -1021,21 +1028,23 @@ EXPORT_SYMBOL(of_cpufreq_power_cooling_register);
10211028
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
10221029
{
10231030
struct cpufreq_cooling_device *cpufreq_dev;
1031+
bool last;
10241032

10251033
if (!cdev)
10261034
return;
10271035

10281036
cpufreq_dev = cdev->devdata;
10291037

10301038
mutex_lock(&cooling_list_lock);
1039+
list_del(&cpufreq_dev->node);
10311040
/* 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)
10331045
cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
10341046
CPUFREQ_POLICY_NOTIFIER);
10351047

1036-
list_del(&cpufreq_dev->node);
1037-
mutex_unlock(&cooling_list_lock);
1038-
10391048
thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
10401049
ida_simple_remove(&cpufreq_ida, cpufreq_dev->id);
10411050
kfree(cpufreq_dev->dyn_power_table);

drivers/thermal/devfreq_cooling.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,22 @@ get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq)
186186
return 0;
187187

188188
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)
190190
opp = dev_pm_opp_find_freq_exact(dev, freq, false);
191191

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+
192198
voltage = dev_pm_opp_get_voltage(opp) / 1000; /* mV */
193199
dev_pm_opp_put(opp);
194200

195201
if (voltage == 0) {
196-
dev_warn_ratelimited(dev,
197-
"Failed to get voltage for frequency %lu: %ld\n",
198-
freq, IS_ERR(opp) ? PTR_ERR(opp) : 0);
202+
dev_err_ratelimited(dev,
203+
"Failed to get voltage for frequency %lu\n",
204+
freq);
199205
return 0;
200206
}
201207

0 commit comments

Comments
 (0)