cpufreq: remove race while accessing cur_policy
Bibek Basu [Fri, 9 May 2014 11:40:35 +0000 (16:40 +0530)]
While accessing cur_policy during executing events
CPUFREQ_GOV_START, CPUFREQ_GOV_STOP, CPUFREQ_GOV_LIMITS
same mutex lock is not taken, dbs_data->mutex, which leads
to race and data corruption while running continious suspend
resume test.

Bug 1455519

Change-Id: I6b385578c791648681746b749d33f671d00154f3
Signed-off-by: Bibek Basu <bbasu@nvidia.com>
Reviewed-on: http://git-master/r/407589
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>

drivers/cpufreq/cpufreq_governor.c

index a727267..3a87379 100644 (file)
@@ -8,6 +8,7 @@
  *             (C) 2003 Jun Nakajima <jun.nakajima@intel.com>
  *             (C) 2009 Alexander Clouter <alex@digriz.org.uk>
  *             (c) 2012 Viresh Kumar <viresh.kumar@linaro.org>
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -364,6 +365,11 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                break;
 
        case CPUFREQ_GOV_LIMITS:
+               mutex_lock(&dbs_data->mutex);
+               if (!cpu_cdbs->cur_policy) {
+                       mutex_unlock(&dbs_data->mutex);
+                       break;
+               }
                mutex_lock(&cpu_cdbs->timer_mutex);
                if (policy->max < cpu_cdbs->cur_policy->cur)
                        __cpufreq_driver_target(cpu_cdbs->cur_policy,
@@ -373,6 +379,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                                        policy->min, CPUFREQ_RELATION_L);
                dbs_check_cpu(dbs_data, cpu);
                mutex_unlock(&cpu_cdbs->timer_mutex);
+               mutex_unlock(&dbs_data->mutex);
                break;
        }
        return 0;