diff options
author | Richard Cochran <rcochran@linutronix.de> | 2016-03-11 03:43:07 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-03-17 20:49:01 -0400 |
commit | c75361c0b08a59d3c9863a5a673ae039d5118c35 (patch) | |
tree | d406a57cfcbdf87374400d333f28dc47b064db05 /drivers/cpufreq/cpufreq.c | |
parent | 4fec7ad5f637159525265a45f66482cf8817b45f (diff) |
cpufreq: Make cpufreq_quick_get() safe to call
The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
its fields without taking the associated lock, cpufreq_driver_lock.
Without the locking, nothing guarantees that 'cpufreq_driver' remains
consistent during the call. This patch fixes the issue by taking the lock
before accessing the data structure.
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 4c7825856eab..f870399f00b1 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -1401,9 +1401,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu) | |||
1401 | { | 1401 | { |
1402 | struct cpufreq_policy *policy; | 1402 | struct cpufreq_policy *policy; |
1403 | unsigned int ret_freq = 0; | 1403 | unsigned int ret_freq = 0; |
1404 | unsigned long flags; | ||
1404 | 1405 | ||
1405 | if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) | 1406 | read_lock_irqsave(&cpufreq_driver_lock, flags); |
1406 | return cpufreq_driver->get(cpu); | 1407 | |
1408 | if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { | ||
1409 | ret_freq = cpufreq_driver->get(cpu); | ||
1410 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); | ||
1411 | return ret_freq; | ||
1412 | } | ||
1413 | |||
1414 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); | ||
1407 | 1415 | ||
1408 | policy = cpufreq_cpu_get(cpu); | 1416 | policy = cpufreq_cpu_get(cpu); |
1409 | if (policy) { | 1417 | if (policy) { |