Skip to contentSkip to conversation

cpufreq: Avoid creating sysfs link for offline CPUs

PATCH In review Zihuan Zhang 2 participants 3 messages Jul 21, 2025 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: Avoid creating sysfs link for offline CPUs

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.

---
 drivers/cpufreq/cpufreq.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq.c +5 -5
index d7426e1d8bdd..0a77892d366c 100644
@@ -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;
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · 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.

Why?

Quoted 2 lines

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!

Quoted 28 lines
---
 drivers/cpufreq/cpufreq.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq.c +5 -6
index d7426e1d8bdd..0a77892d366c 100644
@@ -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 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · 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.

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.

Quoted 32 lines
Quoted 2 lines

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!

Quoted 28 lines
---
  drivers/cpufreq/cpufreq.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/cpufreq/cpufreq.c +5 -6
index d7426e1d8bdd..0a77892d366c 100644
@@ -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;
  }
--