diff mbox

[V5,09/14] cpufreq: add/remove sysfs links via cpufreq_add_remove_dev_symlink()

Message ID 93a3bfbe26dfa1c298e21da369e6ed37fca1da34.1431924457.git.viresh.kumar@linaro.org
State New
Headers show

Commit Message

Viresh Kumar May 18, 2015, 5:13 a.m. UTC
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(-)

Comments

Viresh Kumar May 23, 2015, 3:41 a.m. UTC | #1
On 23-05-15, 01:28, Rafael J. Wysocki wrote:
> (The last statement line is likely longer than 80 chars, but that's fine.)

No, it isn't.

I am dropping this patch and merging it with the next one. Otherwise
it generates warnings about routine defined but not used. So I will be
resending 10/14 and that replaces 9-10/14.

Thanks.
diff mbox

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d7fc3d9294f8..b5e883f497dd 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -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)