cpufreq: Protected access of policy attribute
Puneet Saxena [Thu, 7 Jun 2012 13:49:59 +0000 (18:49 +0530)]
It takes read RW semaphore to access policy governor

bug 997731

Change-Id: Ibdc3dd54cf6076c0fef4bc58f144e4bcb4631d76
Signed-off-by: Puneet Saxena <puneets@nvidia.com>
Reviewed-on: http://git-master/r/107079
GVS: Gerrit_Virtual_Submit
Reviewed-by: Sang-Hun Lee <sanlee@nvidia.com>
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>

drivers/cpufreq/cpufreq.c

index e1eed49..79383fc 100644 (file)
@@ -1824,13 +1824,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;