[PATCH v2] cpufreq/longhaul: handle NULL policy in longhaul_exit

Dennis Beier posted 1 patch 1 month ago
drivers/cpufreq/longhaul.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH v2] cpufreq/longhaul: handle NULL policy in longhaul_exit
Posted by Dennis Beier 1 month ago
longhaul_exit() was calling cpufreq_cpu_get(0) without checking
for a NULL policy pointer. On some systems, this could lead to a
NULL dereference and a kernel warning or panic.

This patch adds a check using unlikely() and returns early if the
policy is NULL.

Bugzilla: #219962

Signed-off-by: Dennis Beier <nanovim@gmail.com>
---
 drivers/cpufreq/longhaul.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index ba0e08c8486a..49e76b44468a 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -953,6 +953,9 @@ static void __exit longhaul_exit(void)
 	struct cpufreq_policy *policy = cpufreq_cpu_get(0);
 	int i;
 
+	if (unlikely(!policy))
+		return;
+
 	for (i = 0; i < numscales; i++) {
 		if (mults[i] == maxmult) {
 			struct cpufreq_freqs freqs;
-- 
2.51.0
Re: [PATCH v2] cpufreq/longhaul: handle NULL policy in longhaul_exit
Posted by Viresh Kumar 1 month ago
On 30-08-25, 16:43, Dennis Beier wrote:
> longhaul_exit() was calling cpufreq_cpu_get(0) without checking
> for a NULL policy pointer. On some systems, this could lead to a
> NULL dereference and a kernel warning or panic.
> 
> This patch adds a check using unlikely() and returns early if the
> policy is NULL.
> 
> Bugzilla: #219962
> 
> Signed-off-by: Dennis Beier <nanovim@gmail.com>
> ---
>  drivers/cpufreq/longhaul.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
> index ba0e08c8486a..49e76b44468a 100644
> --- a/drivers/cpufreq/longhaul.c
> +++ b/drivers/cpufreq/longhaul.c
> @@ -953,6 +953,9 @@ static void __exit longhaul_exit(void)
>  	struct cpufreq_policy *policy = cpufreq_cpu_get(0);
>  	int i;
>  
> +	if (unlikely(!policy))
> +		return;
> +
>  	for (i = 0; i < numscales; i++) {
>  		if (mults[i] == maxmult) {
>  			struct cpufreq_freqs freqs;

Applied. Thanks.

-- 
viresh