From ca7d8fa1906d2f2a2c311d337a14b328ed13c414 Mon Sep 17 00:00:00 2001 From: Puneet Saxena Date: Thu, 7 Jun 2012 19:19:59 +0530 Subject: cpufreq: Protected access of policy attribute It takes read RW semaphore to access policy governor bug 997731 Change-Id: Ibdc3dd54cf6076c0fef4bc58f144e4bcb4631d76 Signed-off-by: Puneet Saxena Reviewed-on: http://git-master/r/107079 GVS: Gerrit_Virtual_Submit Reviewed-by: Sang-Hun Lee Reviewed-by: Peter Boonstoppel Reviewed-by: Bharat Nihalani --- drivers/cpufreq/cpufreq.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'drivers/cpufreq/cpufreq.c') diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 629806dc5cbf..02e8c9120d6b 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1805,13 +1805,27 @@ int cpufreq_set_gov(char *target_gov, unsigned int cpu) if (!cur_policy) return -EINVAL; - new_policy = *cur_policy; - if (!strncmp(cur_policy->governor->name, target_gov, - strlen(target_gov))) { - /* Target governer & current governer is same */ + if (lock_policy_rwsem_read(cur_policy->cpu) < 0) { + ret = -EINVAL; + goto err_out; + } + + if (cur_policy->governor) + ret = strncmp(cur_policy->governor->name, target_gov, + strlen(target_gov)); + else { + unlock_policy_rwsem_read(cur_policy->cpu); + ret = -EINVAL; + goto err_out; + } + unlock_policy_rwsem_read(cur_policy->cpu); + + if (!ret) { + pr_debug(" Target governer & current governer is same\n"); ret = -EINVAL; goto err_out; } else { + new_policy = *cur_policy; if (cpufreq_parse_governor(target_gov, &new_policy.policy, &new_policy.governor)) { ret = -EINVAL; -- cgit v1.2.3