Skip to contentSkip to conversation

cpufreq/longhaul: handle NULL policy in longhaul_exit

PATCH Applied Dennis Beier 2 participants 2 messages Aug 30, 2025 – Sep 1, 2025 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 returns early if the policy is NULL.

Bugzilla: #219962

---
 drivers/cpufreq/longhaul.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/longhaul.c +3 -0
index ba0e08c8486a..49e76b44468a 100644
@@ -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;
Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 19 lines · Dennis Beier

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

---
 drivers/cpufreq/longhaul.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/longhaul.c +0 -0
index ba0e08c8486a..49e76b44468a 100644

drivers/cpufreq/longhaul.c static void __exit longhaul_exit(void) · line 961

Quoted 9 lines
drivers/cpufreq/longhaul.c +3 -0
@@ -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.

Signature · 1 line
viresh