cpufreq: use cpufreq_cpu_get() to avoid cpufreq_get() race conditions
authorAaron Plattner <aplattner@nvidia.com>
Tue, 4 Mar 2014 20:42:15 +0000 (12:42 -0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 6 Mar 2014 12:25:16 +0000 (13:25 +0100)
commit999976e0f6233322a878b0b7148c810544d6c8a8
treedf07413e3d9018e7ee7c439bc697c93cb52a61b3
parent0414855fdc4a40da05221fc6062cccbc0c30f169
cpufreq: use cpufreq_cpu_get() to avoid cpufreq_get() race conditions

If a module calls cpufreq_get while cpufreq is initializing, it's
possible for it to be called after cpufreq_driver is set but before
cpufreq_cpu_data is written during subsys_interface_register.  This
happens because cpufreq_get doesn't take the cpufreq_driver_lock
around its use of cpufreq_cpu_data.

Fix this by using cpufreq_cpu_get(cpu) to look up the policy rather
than reading it out of cpufreq_cpu_data directly.  cpufreq_cpu_get()
takes the appropriate locks to prevent this race from happening.

Since it's possible for policy to be NULL if the caller passes in an
invalid CPU number or calls the function before cpufreq is initialized,
delete the BUG_ON(!policy) and simply return 0.  Don't try to return
-ENOENT because that's negative and the function returns an unsigned
integer.

References: https://bbs.archlinux.org/viewtopic.php?id=177934
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Cc: 3.13+ <stable@vger.kernel.org> # 3.13+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c