cpufreq: Extract non-interface related stuff from cpufreq_add_dev_interface

cpufreq_add_dev_interface() includes the work of exposing the interface
to the device, as well as a lot of unrelated stuff. Move the latter to
cpufreq_add_dev(), where it is more appropriate.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Srivatsa S. Bhat 2013-07-30 04:24:23 +05:30 committed by Rafael J. Wysocki
parent e9698cc5d2
commit e18f1682bc

View file

@ -835,11 +835,8 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
struct cpufreq_policy *policy, struct cpufreq_policy *policy,
struct device *dev) struct device *dev)
{ {
struct cpufreq_policy new_policy;
struct freq_attr **drv_attr; struct freq_attr **drv_attr;
unsigned long flags;
int ret = 0; int ret = 0;
unsigned int j;
/* prepare interface data */ /* prepare interface data */
ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
@ -871,17 +868,23 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
goto err_out_kobj_put; goto err_out_kobj_put;
} }
write_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu(j, policy->cpus) {
per_cpu(cpufreq_cpu_data, j) = policy;
per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
}
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
ret = cpufreq_add_dev_symlink(cpu, policy); ret = cpufreq_add_dev_symlink(cpu, policy);
if (ret) if (ret)
goto err_out_kobj_put; goto err_out_kobj_put;
return ret;
err_out_kobj_put:
kobject_put(&policy->kobj);
wait_for_completion(&policy->kobj_unregister);
return ret;
}
static void cpufreq_init_policy(struct cpufreq_policy *policy)
{
struct cpufreq_policy new_policy;
int ret = 0;
memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
/* assure that the starting sequence is run in __cpufreq_set_policy */ /* assure that the starting sequence is run in __cpufreq_set_policy */
policy->governor = NULL; policy->governor = NULL;
@ -896,12 +899,6 @@ static int cpufreq_add_dev_interface(unsigned int cpu,
if (cpufreq_driver->exit) if (cpufreq_driver->exit)
cpufreq_driver->exit(policy); cpufreq_driver->exit(policy);
} }
return ret;
err_out_kobj_put:
kobject_put(&policy->kobj);
wait_for_completion(&policy->kobj_unregister);
return ret;
} }
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
@ -1075,10 +1072,19 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
} }
#endif #endif
write_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu(j, policy->cpus) {
per_cpu(cpufreq_cpu_data, j) = policy;
per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
}
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
ret = cpufreq_add_dev_interface(cpu, policy, dev); ret = cpufreq_add_dev_interface(cpu, policy, dev);
if (ret) if (ret)
goto err_out_unregister; goto err_out_unregister;
cpufreq_init_policy(policy);
kobject_uevent(&policy->kobj, KOBJ_ADD); kobject_uevent(&policy->kobj, KOBJ_ADD);
module_put(cpufreq_driver->owner); module_put(cpufreq_driver->owner);
pr_debug("initialization complete\n"); pr_debug("initialization complete\n");
@ -1087,8 +1093,11 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
err_out_unregister: err_out_unregister:
write_lock_irqsave(&cpufreq_driver_lock, flags); write_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu(j, policy->cpus) for_each_cpu(j, policy->cpus) {
per_cpu(cpufreq_cpu_data, j) = NULL; per_cpu(cpufreq_cpu_data, j) = NULL;
if (j != cpu)
per_cpu(cpufreq_policy_cpu, j) = -1;
}
write_unlock_irqrestore(&cpufreq_driver_lock, flags); write_unlock_irqrestore(&cpufreq_driver_lock, flags);
kobject_put(&policy->kobj); kobject_put(&policy->kobj);