thermal: cpu_cooling: Avoid accessing potentially freed structures

After the lock is dropped, it is possible that the cpufreq_dev gets
freed before we call get_level() and that can cause kernel to crash.

Drop the lock after we are done using the structure.

Cc: 4.2+ <[email protected]> # 4.2+
Fixes: 02373d7c69 ("thermal: cpu_cooling: fix lockdep problems in cpu_cooling")
Signed-off-by: Viresh Kumar <[email protected]>
Reviewed-by: Lukasz Luba <[email protected]>
Tested-by: Lukasz Luba <[email protected]>
Signed-off-by: Eduardo Valentin <[email protected]>
This commit is contained in:
Viresh Kumar 2017-04-25 15:57:08 +05:30 • committed by Eduardo Valentin
commit 289d72afdd

View file

@ -153,8 +153,10 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
mutex_lock(&cooling_list_lock);
list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) {
unsigned long level = get_level(cpufreq_dev, freq);
mutex_unlock(&cooling_list_lock);
return get_level(cpufreq_dev, freq);
return level;
}
}
mutex_unlock(&cooling_list_lock);