Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get()

Currently there is an unlikely case where cpufreq_cpu_get() returns a
NULL policy and this will cause a NULL pointer dereference later on.

Fix this by passing the policy to transition_frequency_fidvid() from
the caller and hence eliminating the need for the cpufreq_cpu_get()
and cpufreq_cpu_put().

Thanks to Viresh Kumar for suggesting the fix.

Addresses-Coverity: ("Dereference null return")
Fixes: b43a7ffbf33b ("cpufreq: Notify all policy->cpus in cpufreq_notify_transition()")
Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Colin Ian King and committed by
Rafael J. Wysocki
943bdd0c 17ffd358

+3 -6
+3 -6
drivers/cpufreq/powernow-k8.c
··· 878 878 879 879 /* Take a frequency, and issue the fid/vid transition command */ 880 880 static int transition_frequency_fidvid(struct powernow_k8_data *data, 881 - unsigned int index) 881 + unsigned int index, 882 + struct cpufreq_policy *policy) 882 883 { 883 - struct cpufreq_policy *policy; 884 884 u32 fid = 0; 885 885 u32 vid = 0; 886 886 int res; ··· 911 911 smp_processor_id(), fid, vid); 912 912 freqs.old = find_khz_freq_from_fid(data->currfid); 913 913 freqs.new = find_khz_freq_from_fid(fid); 914 - 915 - policy = cpufreq_cpu_get(smp_processor_id()); 916 - cpufreq_cpu_put(policy); 917 914 918 915 cpufreq_freq_transition_begin(policy, &freqs); 919 916 res = transition_fid_vid(data, fid, vid); ··· 966 969 967 970 powernow_k8_acpi_pst_values(data, newstate); 968 971 969 - ret = transition_frequency_fidvid(data, newstate); 972 + ret = transition_frequency_fidvid(data, newstate, pol); 970 973 971 974 if (ret) { 972 975 pr_err("transition frequency failed\n");