linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] cpufreq: Avoid creating sysfs link for offline CPUs
@ 2025-07-21 15:36 Zihuan Zhang
  2025-07-21 15:51 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Zihuan Zhang @ 2025-07-21 15:36 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar; +Cc: linux-pm, linux-kernel, Zihuan Zhang

Currently, cpufreq_add_dev() attempts to create a sysfs link
even when the target CPU is offline. Although guarded by a NULL
check on cpufreq_policy, this behavior is not strictly correct,
since offline CPUs shouldn't have their sysfs interface created.

This patch cleans up the logic to only add the sysfs link
when the CPU is online and cpufreq policy is properly initialized.

Signed-off-by: Zihuan Zhang <zzhwaxy.kernel@gmail.com>
---
 drivers/cpufreq/cpufreq.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d7426e1d8bdd..0a77892d366c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1660,12 +1660,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
 		ret = cpufreq_online(cpu);
 		if (ret)
 			return ret;
-	}
 
-	/* Create sysfs link on CPU registration */
-	policy = per_cpu(cpufreq_cpu_data, cpu);
-	if (policy)
-		add_cpu_dev_symlink(policy, cpu, dev);
+		/* Create sysfs link on CPU registration */
+		policy = per_cpu(cpufreq_cpu_data, cpu);
+		if (policy)
+			add_cpu_dev_symlink(policy, cpu, dev);
+	}
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] cpufreq: Avoid creating sysfs link for offline CPUs
  2025-07-21 15:36 [PATCH v1] cpufreq: Avoid creating sysfs link for offline CPUs Zihuan Zhang
@ 2025-07-21 15:51 ` Rafael J. Wysocki
  2025-07-21 16:02   ` Zihuan Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-07-21 15:51 UTC (permalink / raw)
  To: Zihuan Zhang; +Cc: Rafael J . Wysocki, Viresh Kumar, linux-pm, linux-kernel

On Mon, Jul 21, 2025 at 5:37 PM Zihuan Zhang <zzhwaxy.kernel@gmail.com> wrote:
>
> Currently, cpufreq_add_dev() attempts to create a sysfs link
> even when the target CPU is offline. Although guarded by a NULL
> check on cpufreq_policy, this behavior is not strictly correct,
> since offline CPUs shouldn't have their sysfs interface created.

Why?

> This patch cleans up the logic to only add the sysfs link
> when the CPU is online and cpufreq policy is properly initialized.

I don't really think that this change is necessary.  Thanks!

> Signed-off-by: Zihuan Zhang <zzhwaxy.kernel@gmail.com>
> ---
>  drivers/cpufreq/cpufreq.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index d7426e1d8bdd..0a77892d366c 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1660,12 +1660,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
>                 ret = cpufreq_online(cpu);
>                 if (ret)
>                         return ret;
> -       }
>
> -       /* Create sysfs link on CPU registration */
> -       policy = per_cpu(cpufreq_cpu_data, cpu);
> -       if (policy)
> -               add_cpu_dev_symlink(policy, cpu, dev);
> +               /* Create sysfs link on CPU registration */
> +               policy = per_cpu(cpufreq_cpu_data, cpu);
> +               if (policy)
> +                       add_cpu_dev_symlink(policy, cpu, dev);
> +       }
>
>         return 0;
>  }
> --

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] cpufreq: Avoid creating sysfs link for offline CPUs
  2025-07-21 15:51 ` Rafael J. Wysocki
@ 2025-07-21 16:02   ` Zihuan Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Zihuan Zhang @ 2025-07-21 16:02 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Viresh Kumar, linux-pm, linux-kernel


在 2025/7/21 23:51, Rafael J. Wysocki 写道:
> On Mon, Jul 21, 2025 at 5:37 PM Zihuan Zhang <zzhwaxy.kernel@gmail.com> wrote:
>> Currently, cpufreq_add_dev() attempts to create a sysfs link
>> even when the target CPU is offline. Although guarded by a NULL
>> check on cpufreq_policy, this behavior is not strictly correct,
>> since offline CPUs shouldn't have their sysfs interface created.
> Why?


Thanks for the comment.

The idea was to avoid unnecessary sysfs operations for CPUs that are 
offline, even though the existing checks make it safe. But I understand 
it's not strictly needed — I'm fine with dropping it.

>> This patch cleans up the logic to only add the sysfs link
>> when the CPU is online and cpufreq policy is properly initialized.
> I don't really think that this change is necessary.  Thanks!
>
>> Signed-off-by: Zihuan Zhang <zzhwaxy.kernel@gmail.com>
>> ---
>>   drivers/cpufreq/cpufreq.c | 10 +++++-----
>>   1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index d7426e1d8bdd..0a77892d366c 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -1660,12 +1660,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
>>                  ret = cpufreq_online(cpu);
>>                  if (ret)
>>                          return ret;
>> -       }
>>
>> -       /* Create sysfs link on CPU registration */
>> -       policy = per_cpu(cpufreq_cpu_data, cpu);
>> -       if (policy)
>> -               add_cpu_dev_symlink(policy, cpu, dev);
>> +               /* Create sysfs link on CPU registration */
>> +               policy = per_cpu(cpufreq_cpu_data, cpu);
>> +               if (policy)
>> +                       add_cpu_dev_symlink(policy, cpu, dev);
>> +       }
>>
>>          return 0;
>>   }
>> --

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-21 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-21 15:36 [PATCH v1] cpufreq: Avoid creating sysfs link for offline CPUs Zihuan Zhang
2025-07-21 15:51 ` Rafael J. Wysocki
2025-07-21 16:02   ` Zihuan Zhang

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).