Skip to contentSkip to conversation

cpufreq/longhaul: handle NULL policy in longhaul_exit

PATCH Superseded Dennis Beier 1 participant 1 message Aug 28, 2025 CPU frequency scaling framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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