]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get()
authorColin Ian King <colin.king@canonical.com>
Tue, 5 Jan 2021 10:19:57 +0000 (10:19 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 17 Jan 2021 12:55:13 +0000 (13:55 +0100)
commit 943bdd0cecad06da8392a33093230e30e501eccc upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/cpufreq/powernow-k8.c

index 0b5bf135b0907491a226353f2127cc51c9c13cde..59f16807921ad829ede4e0373b0ea811beaa9256 100644 (file)
@@ -887,9 +887,9 @@ static int get_transition_latency(struct powernow_k8_data *data)
 
 /* Take a frequency, and issue the fid/vid transition command */
 static int transition_frequency_fidvid(struct powernow_k8_data *data,
-               unsigned int index)
+               unsigned int index,
+               struct cpufreq_policy *policy)
 {
-       struct cpufreq_policy *policy;
        u32 fid = 0;
        u32 vid = 0;
        int res;
@@ -921,9 +921,6 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,
        freqs.old = find_khz_freq_from_fid(data->currfid);
        freqs.new = find_khz_freq_from_fid(fid);
 
-       policy = cpufreq_cpu_get(smp_processor_id());
-       cpufreq_cpu_put(policy);
-
        cpufreq_freq_transition_begin(policy, &freqs);
        res = transition_fid_vid(data, fid, vid);
        cpufreq_freq_transition_end(policy, &freqs, res);
@@ -978,7 +975,7 @@ static long powernowk8_target_fn(void *arg)
 
        powernow_k8_acpi_pst_values(data, newstate);
 
-       ret = transition_frequency_fidvid(data, newstate);
+       ret = transition_frequency_fidvid(data, newstate, pol);
 
        if (ret) {
                pr_err("transition frequency failed\n");