* [PATCH][V3] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get
@ 2021-01-05 10:19 Colin King
2021-01-05 10:21 ` Viresh Kumar
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2021-01-05 10:19 UTC (permalink / raw)
To: Rafael J . Wysocki, Viresh Kumar, Stephen Warren, linux-pm
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
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()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
V2: pass the policy to transition_frequency_fidvid rather than add
a null pointer check on the return from a cpufreq_cpu_get call.
V3: update subject line to match the fix
---
drivers/cpufreq/powernow-k8.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 0acc9e241cd7..b9ccb6a3dad9 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -878,9 +878,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;
@@ -912,9 +912,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);
@@ -969,7 +966,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");
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][V3] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get
2021-01-05 10:19 [PATCH][V3] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get Colin King
@ 2021-01-05 10:21 ` Viresh Kumar
2021-01-07 16:39 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2021-01-05 10:21 UTC (permalink / raw)
To: Colin King
Cc: Rafael J . Wysocki, Stephen Warren, linux-pm, kernel-janitors,
linux-kernel
On 05-01-21, 10:19, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>
> V2: pass the policy to transition_frequency_fidvid rather than add
> a null pointer check on the return from a cpufreq_cpu_get call.
> V3: update subject line to match the fix
>
> ---
> drivers/cpufreq/powernow-k8.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][V3] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get
2021-01-05 10:21 ` Viresh Kumar
@ 2021-01-07 16:39 ` Rafael J. Wysocki
0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2021-01-07 16:39 UTC (permalink / raw)
To: Viresh Kumar, Colin King
Cc: Rafael J . Wysocki, Stephen Warren, Linux PM, kernel-janitors,
Linux Kernel Mailing List
On Tue, Jan 5, 2021 at 11:22 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 05-01-21, 10:19, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > 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()")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >
> > V2: pass the policy to transition_frequency_fidvid rather than add
> > a null pointer check on the return from a cpufreq_cpu_get call.
> > V3: update subject line to match the fix
> >
> > ---
> > drivers/cpufreq/powernow-k8.c | 9 +++------
> > 1 file changed, 3 insertions(+), 6 deletions(-)
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Applied as 5.11-rc material, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-07 16:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 10:19 [PATCH][V3] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get Colin King
2021-01-05 10:21 ` Viresh Kumar
2021-01-07 16:39 ` 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;
as well as URLs for NNTP newsgroup(s).