@@ -957,25 +957,42 @@ void cpufreq_sysfs_remove_file(const struct attribute *attr)
}
EXPORT_SYMBOL(cpufreq_sysfs_remove_file);
-/* symlink affected CPUs */
-static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy)
+static inline int add_remove_cpu_dev_symlink(struct cpufreq_policy *policy,
+ int cpu, bool add)
+{
+ struct device *cpu_dev;
+
+ pr_debug("%s: %s symlink for CPU: %u\n", __func__,
+ add ? "Adding" : "Removing", cpu);
+
+ cpu_dev = get_cpu_device(cpu);
+ if (WARN_ON(!cpu_dev))
+ return 0;
+
+ if (add)
+ return sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
+ "cpufreq");
+
+ sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
+ return 0;
+}
+
+/* Add/remove symlinks for all affected CPUs */
+static int cpufreq_add_remove_dev_symlink(struct cpufreq_policy *policy,
+ bool add)
{
unsigned int j;
int ret = 0;
for_each_cpu(j, policy->cpus) {
- struct device *cpu_dev;
-
if (j == policy->kobj_cpu)
continue;
- pr_debug("Adding link for CPU: %u\n", j);
- cpu_dev = get_cpu_device(j);
- ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
- "cpufreq");
+ ret = add_remove_cpu_dev_symlink(policy, j, add);
if (ret)
break;
}
+
return ret;
}
@@ -1009,7 +1026,7 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy,
return ret;
}
- return cpufreq_add_dev_symlink(policy);
+ return cpufreq_add_remove_dev_symlink(policy, true);
}
static void cpufreq_init_policy(struct cpufreq_policy *policy)
Later patches would require us to add/remove all sysfs links together. Create another routine cpufreq_add_remove_dev_symlink() to do that. This is a preparatory step for the next patch and is done separately for easier reviews. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> --- drivers/cpufreq/cpufreq.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)