* [PATCH RESEND] cpufreq/longhaul: handle NULL policy in longhaul_exit
@ 2025-08-28 21:29 Dennis Beier
2025-08-29 4:15 ` Viresh Kumar
0 siblings, 1 reply; 2+ messages in thread
From: Dennis Beier @ 2025-08-28 21:29 UTC (permalink / raw)
To: rafael, viresh.kumar; +Cc: linux-pm, linux-kernel, Dennis Beier
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
Signed-off-by: Dennis Beier <nanovim@gmail.com>
---
drivers/cpufreq/longhaul.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index ba0e08c8486a..9698d56bfe6c 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -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;
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND] cpufreq/longhaul: handle NULL policy in longhaul_exit
2025-08-28 21:29 [PATCH RESEND] cpufreq/longhaul: handle NULL policy in longhaul_exit Dennis Beier
@ 2025-08-29 4:15 ` Viresh Kumar
0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2025-08-29 4:15 UTC (permalink / raw)
To: Dennis Beier; +Cc: rafael, linux-pm, linux-kernel
On 28-08-25, 23:29, Dennis Beier wrote:
>
> Resending this patch to include cpufreq maintainers.
This should have been added ...
> ---
>
> 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
>
> Signed-off-by: Dennis Beier <nanovim@gmail.com>
>
> ---
... 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 <nanovim@gmail.com>
Date: Thu Aug 28 23:29:36 2025 +0200
cpufreq/longhaul: handle NULL policy in longhaul_exit
Resending this patch to include cpufreq maintainers.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/longhaul.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
> drivers/cpufreq/longhaul.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
> index ba0e08c8486a..9698d56bfe6c 100644
> --- a/drivers/cpufreq/longhaul.c
> +++ b/drivers/cpufreq/longhaul.c
> @@ -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.
> + 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.
> +
> + return;
> + }
> +
>
> - for (i = 0; i < numscales; i++) {
> + for (int i = 0; i < numscales; i++) {
> if (mults[i] == maxmult) {
> struct cpufreq_freqs freqs;
>
> --
> 2.50.1
--
viresh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-29 4:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28 21:29 [PATCH RESEND] cpufreq/longhaul: handle NULL policy in longhaul_exit Dennis Beier
2025-08-29 4:15 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).