aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2006-07-06 15:30:26 -0400
committerDave Jones <davej@redhat.com>2006-07-31 18:37:06 -0400
commit3bcb09a35641f2840bd59d8f82154f830dca282c (patch)
tree57fc63ed401b27573d88f322487a6554f006c883 /drivers/cpufreq/cpufreq.c
parent32deb2d5c4c291d7d9a73198dc357a151e4b978c (diff)
[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: Jeremy Fitzhardinge <jeremy@goop.org> Signed-off-by: Dave Jones <davej@redhat.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r--drivers/cpufreq/cpufreq.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index ad996c772c8b..9b416372a8e4 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -284,39 +284,52 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
284 * SYSFS INTERFACE * 284 * SYSFS INTERFACE *
285 *********************************************************************/ 285 *********************************************************************/
286 286
287static struct cpufreq_governor *__find_governor(const char *str_governor)
288{
289 struct cpufreq_governor *t;
290
291 list_for_each_entry(t, &cpufreq_governor_list, governor_list)
292 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN))
293 return t;
294
295 return NULL;
296}
297
287/** 298/**
288 * cpufreq_parse_governor - parse a governor string 299 * cpufreq_parse_governor - parse a governor string
289 */ 300 */
290static int cpufreq_parse_governor (char *str_governor, unsigned int *policy, 301static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
291 struct cpufreq_governor **governor) 302 struct cpufreq_governor **governor)
292{ 303{
304 int err = -EINVAL;
305
293 if (!cpufreq_driver) 306 if (!cpufreq_driver)
294 return -EINVAL; 307 goto out;
308
295 if (cpufreq_driver->setpolicy) { 309 if (cpufreq_driver->setpolicy) {
296 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { 310 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
297 *policy = CPUFREQ_POLICY_PERFORMANCE; 311 *policy = CPUFREQ_POLICY_PERFORMANCE;
298 return 0; 312 err = 0;
299 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { 313 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
300 *policy = CPUFREQ_POLICY_POWERSAVE; 314 *policy = CPUFREQ_POLICY_POWERSAVE;
301 return 0; 315 err = 0;
302 } 316 }
303 return -EINVAL; 317 } else if (cpufreq_driver->target) {
304 } else {
305 struct cpufreq_governor *t; 318 struct cpufreq_governor *t;
319
306 mutex_lock(&cpufreq_governor_mutex); 320 mutex_lock(&cpufreq_governor_mutex);
307 if (!cpufreq_driver || !cpufreq_driver->target) 321
308 goto out; 322 t = __find_governor(str_governor);
309 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 323
310 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) { 324 if (t != NULL) {
311 *governor = t; 325 *governor = t;
312 mutex_unlock(&cpufreq_governor_mutex); 326 err = 0;
313 return 0;
314 }
315 } 327 }
316out: 328
317 mutex_unlock(&cpufreq_governor_mutex); 329 mutex_unlock(&cpufreq_governor_mutex);
318 } 330 }
319 return -EINVAL; 331 out:
332 return err;
320} 333}
321 334
322 335
@@ -1265,23 +1278,21 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1265 1278
1266int cpufreq_register_governor(struct cpufreq_governor *governor) 1279int cpufreq_register_governor(struct cpufreq_governor *governor)
1267{ 1280{
1268 struct cpufreq_governor *t; 1281 int err;
1269 1282
1270 if (!governor) 1283 if (!governor)
1271 return -EINVAL; 1284 return -EINVAL;
1272 1285
1273 mutex_lock(&cpufreq_governor_mutex); 1286 mutex_lock(&cpufreq_governor_mutex);
1274 1287
1275 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 1288 err = -EBUSY;
1276 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { 1289 if (__find_governor(governor->name) == NULL) {
1277 mutex_unlock(&cpufreq_governor_mutex); 1290 err = 0;
1278 return -EBUSY; 1291 list_add(&governor->governor_list, &cpufreq_governor_list);
1279 }
1280 } 1292 }
1281 list_add(&governor->governor_list, &cpufreq_governor_list);
1282 1293
1283 mutex_unlock(&cpufreq_governor_mutex); 1294 mutex_unlock(&cpufreq_governor_mutex);
1284 return 0; 1295 return err;
1285} 1296}
1286EXPORT_SYMBOL_GPL(cpufreq_register_governor); 1297EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1287 1298