Commit 3bcb09a3 authored by Jeremy Fitzhardinge's avatar Jeremy Fitzhardinge Committed by Dave Jones

[CPUFREQ] [1/2] add __find_governor helper and clean up some error handling.

Adds a __find_governor() helper function to look up a governor by
name.  Also restructures some error handling to conform to the
"single-exit" model which is generally preferred for kernel code.
Signed-off-by: default avatarJeremy Fitzhardinge <jeremy@goop.org>
Signed-off-by: default avatarDave Jones <davej@redhat.com>
parent 32deb2d5
...@@ -284,39 +284,52 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_transition); ...@@ -284,39 +284,52 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
* SYSFS INTERFACE * * SYSFS INTERFACE *
*********************************************************************/ *********************************************************************/
static struct cpufreq_governor *__find_governor(const char *str_governor)
{
struct cpufreq_governor *t;
list_for_each_entry(t, &cpufreq_governor_list, governor_list)
if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN))
return t;
return NULL;
}
/** /**
* cpufreq_parse_governor - parse a governor string * cpufreq_parse_governor - parse a governor string
*/ */
static int cpufreq_parse_governor (char *str_governor, unsigned int *policy, static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
struct cpufreq_governor **governor) struct cpufreq_governor **governor)
{ {
int err = -EINVAL;
if (!cpufreq_driver) if (!cpufreq_driver)
return -EINVAL; goto out;
if (cpufreq_driver->setpolicy) { if (cpufreq_driver->setpolicy) {
if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
*policy = CPUFREQ_POLICY_PERFORMANCE; *policy = CPUFREQ_POLICY_PERFORMANCE;
return 0; err = 0;
} else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
*policy = CPUFREQ_POLICY_POWERSAVE; *policy = CPUFREQ_POLICY_POWERSAVE;
return 0; err = 0;
} }
return -EINVAL; } else if (cpufreq_driver->target) {
} else {
struct cpufreq_governor *t; struct cpufreq_governor *t;
mutex_lock(&cpufreq_governor_mutex); mutex_lock(&cpufreq_governor_mutex);
if (!cpufreq_driver || !cpufreq_driver->target)
goto out; t = __find_governor(str_governor);
list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) { if (t != NULL) {
*governor = t; *governor = t;
mutex_unlock(&cpufreq_governor_mutex); err = 0;
return 0;
}
} }
out:
mutex_unlock(&cpufreq_governor_mutex); mutex_unlock(&cpufreq_governor_mutex);
} }
return -EINVAL; out:
return err;
} }
...@@ -1265,23 +1278,21 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) ...@@ -1265,23 +1278,21 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
int cpufreq_register_governor(struct cpufreq_governor *governor) int cpufreq_register_governor(struct cpufreq_governor *governor)
{ {
struct cpufreq_governor *t; int err;
if (!governor) if (!governor)
return -EINVAL; return -EINVAL;
mutex_lock(&cpufreq_governor_mutex); mutex_lock(&cpufreq_governor_mutex);
list_for_each_entry(t, &cpufreq_governor_list, governor_list) { err = -EBUSY;
if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { if (__find_governor(governor->name) == NULL) {
mutex_unlock(&cpufreq_governor_mutex); err = 0;
return -EBUSY; list_add(&governor->governor_list, &cpufreq_governor_list);
}
} }
list_add(&governor->governor_list, &cpufreq_governor_list);
mutex_unlock(&cpufreq_governor_mutex); mutex_unlock(&cpufreq_governor_mutex);
return 0; return err;
} }
EXPORT_SYMBOL_GPL(cpufreq_register_governor); EXPORT_SYMBOL_GPL(cpufreq_register_governor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment