Skip to contentSkip to conversation

cpufreq/longhaul: handle NULL policy in longhaul_exit

PATCH RESEND Superseded Dennis Beier 2 participants 2 messages Aug 28, 2025 – Aug 29, 2025 CPU frequency scaling framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 cpufreq/longhaul: handle NULL policy in longhaul_exit

Resending this patch to include cpufreq maintainers.

---

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 prints a warning if the policy is NULL, then returns early. Also, the loop variable is now declared inside the for-loop to match modern kernel style.

Bugzilla: #219962

---
 drivers/cpufreq/longhaul.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/cpufreq/longhaul.c +7 -2
index ba0e08c8486a..9698d56bfe6c 100644
@@ -951,9 +951,14 @@ static int __init longhaul_init(void)
 static void __exit longhaul_exit(void)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get(0);
-	int i;
+	if (unlikely(!policy)) {
+		pr_warn_once("longhaul_exit: policy is NULL\n");
+
+		return;
+	}
+
 
-	for (i = 0; i < numscales; i++) {
+	for (int i = 0; i < numscales; i++) {
 		if (mults[i] == maxmult) {
 			struct cpufreq_freqs freqs;
 
Signature · 1 line
2.50.1
maintainer
#1 lore raw
Quoted 2 lines · Dennis Beier

Resending this patch to include cpufreq maintainers.

This should have been added ...

Quoted 10 lines

---

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 prints a warning if the policy is NULL, then returns early. Also, the loop variable is now declared inside the for-loop to match modern kernel style.

Quoted 5 lines

Bugzilla: #219962

---

... here. Right now if we apply the patch, it will only contain the top line.

This is what I get now if I apply your patch with git am

Author: Dennis Beier <[email protected]>
Date:   Thu Aug 28 23:29:36 2025 +0200

cpufreq/longhaul: handle NULL policy in longhaul_exit

Resending this patch to include cpufreq maintainers.

---
 drivers/cpufreq/longhaul.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

drivers/cpufreq/longhaul.c static int __init longhaul_init(void) · line 954

Quoted 12 lines
 drivers/cpufreq/longhaul.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/cpufreq/longhaul.c +0 -1
index ba0e08c8486a..9698d56bfe6c 100644
@@ -951,9 +951,14 @@ static int __init longhaul_init(void)
 static void __exit longhaul_exit(void)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get(0);
-	int i;

Please don't make another unnecessary change along with a bug fix. If you really want that, you should do that in a separate patch. Also, it is just not required.

Add a blank line here please.

drivers/cpufreq/longhaul.c static int __init longhaul_init(void) · line 955

Quoted 2 lines
drivers/cpufreq/longhaul.c +2 -0
+	if (unlikely(!policy)) {
+		pr_warn_once("longhaul_exit: policy is NULL\n");

Not sure if the warning is going to be of any use for the user. I would just return silently, the module is going away anyway.

Quoted 12 lines
drivers/cpufreq/longhaul.c +5 -1
+
+		return;
+	}
+
 
-	for (i = 0; i < numscales; i++) {
+	for (int i = 0; i < numscales; i++) {
 		if (mults[i] == maxmult) {
 			struct cpufreq_freqs freqs;
 
Signature · 1 line
2.50.1
Signature · 1 line
viresh