mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpufreq: Make cpufreq_quick_get() safe to call.
@ 2016-03-10 15:10 Richard Cochran
  2016-03-10 22:20 ` Rafael J. Wysocki
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Cochran @ 2016-03-10 15:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: rt, Dirk Brandewie, Rafael J. Wysocki, Viresh Kumar

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.

Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
---
 drivers/cpufreq/cpufreq.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e979ec7..ce02b2b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
 {
 	struct cpufreq_policy *policy;
 	unsigned int ret_freq = 0;
+	unsigned long flags;
+
+	read_lock_irqsave(&cpufreq_driver_lock, flags);
 
 	if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
-		return cpufreq_driver->get(cpu);
+		ret_freq = cpufreq_driver->get(cpu);
+
+	read_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
+	if (ret_freq)
+		return ret_freq;
 
 	policy = cpufreq_cpu_get(cpu);
 	if (policy) {
-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-03-18 23:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 15:10 [PATCH] cpufreq: Make cpufreq_quick_get() safe to call Richard Cochran
2016-03-10 22:20 ` Rafael J. Wysocki
2016-03-11  2:23   ` Rafael J. Wysocki
2016-03-11  8:43     ` [PATCH v2] " Richard Cochran
2016-03-11 23:52       ` Viresh Kumar
2016-03-18 23:34         ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®