All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference
@ 2021-01-04 13:02 ` Colin King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin King @ 2021-01-04 13:02 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 adding a null check and adding an error return.

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>
---
 drivers/cpufreq/powernow-k8.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 0acc9e241cd7..c5368545ba1f 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -913,6 +913,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,
 	freqs.new = find_khz_freq_from_fid(fid);
 
 	policy = cpufreq_cpu_get(smp_processor_id());
+	if (!policy)
+		return 1;
 	cpufreq_cpu_put(policy);
 
 	cpufreq_freq_transition_begin(policy, &freqs);
-- 
2.29.2


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

* [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference
@ 2021-01-04 13:02 ` Colin King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin King @ 2021-01-04 13:02 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 adding a null check and adding an error return.

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>
---
 drivers/cpufreq/powernow-k8.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 0acc9e241cd7..c5368545ba1f 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -913,6 +913,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,
 	freqs.new = find_khz_freq_from_fid(fid);
 
 	policy = cpufreq_cpu_get(smp_processor_id());
+	if (!policy)
+		return 1;
 	cpufreq_cpu_put(policy);
 
 	cpufreq_freq_transition_begin(policy, &freqs);
-- 
2.29.2

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

* Re: [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference
  2021-01-04 13:02 ` Colin King
@ 2021-01-05  3:55   ` Viresh Kumar
  -1 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2021-01-05  3:54 UTC (permalink / raw
  To: Colin King
  Cc: Rafael J . Wysocki, Stephen Warren, linux-pm, kernel-janitors,
	linux-kernel

On 04-01-21, 13:02, 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 adding a null check and adding an error return.
> 
> 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>
> ---
>  drivers/cpufreq/powernow-k8.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> index 0acc9e241cd7..c5368545ba1f 100644
> --- a/drivers/cpufreq/powernow-k8.c
> +++ b/drivers/cpufreq/powernow-k8.c
> @@ -913,6 +913,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,

The caller already has a pointer to the policy, you should rather pass
that here instead of doing cpufreq_cpu_get/put.

>  	freqs.new = find_khz_freq_from_fid(fid);
>  
>  	policy = cpufreq_cpu_get(smp_processor_id());
> +	if (!policy)
> +		return 1;
>  	cpufreq_cpu_put(policy);
>  
>  	cpufreq_freq_transition_begin(policy, &freqs);
> -- 
> 2.29.2

-- 
viresh

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

* Re: [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference
@ 2021-01-05  3:55   ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2021-01-05  3:55 UTC (permalink / raw
  To: Colin King
  Cc: Rafael J . Wysocki, Stephen Warren, linux-pm, kernel-janitors,
	linux-kernel

On 04-01-21, 13:02, 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 adding a null check and adding an error return.
> 
> 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>
> ---
>  drivers/cpufreq/powernow-k8.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> index 0acc9e241cd7..c5368545ba1f 100644
> --- a/drivers/cpufreq/powernow-k8.c
> +++ b/drivers/cpufreq/powernow-k8.c
> @@ -913,6 +913,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,

The caller already has a pointer to the policy, you should rather pass
that here instead of doing cpufreq_cpu_get/put.

>  	freqs.new = find_khz_freq_from_fid(fid);
>  
>  	policy = cpufreq_cpu_get(smp_processor_id());
> +	if (!policy)
> +		return 1;
>  	cpufreq_cpu_put(policy);
>  
>  	cpufreq_freq_transition_begin(policy, &freqs);
> -- 
> 2.29.2

-- 
viresh

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

end of thread, other threads:[~2021-01-05  3:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-04 13:02 [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference Colin King
2021-01-04 13:02 ` Colin King
2021-01-05  3:54 ` Viresh Kumar
2021-01-05  3:55   ` Viresh Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.