diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-29 18:32:00 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-29 18:32:00 -0400 |
commit | 2a99859932281ed6c2ecdd988855f8f6838f6743 (patch) | |
tree | f7991b0a63525c5b9648193b1b3cac64a4ee77e9 /drivers/cpufreq | |
parent | 148519120c6d1f19ad53349683aeae9f228b0b8d (diff) |
cpufreq: Fix cpufreq driver module refcount balance after suspend/resume
Since cpufreq_cpu_put() called by __cpufreq_remove_dev() drops the
driver module refcount, __cpufreq_remove_dev() causes that refcount
to become negative for the cpufreq driver after a suspend/resume
cycle.
This is not the only bad thing that happens there, however, because
kobject_put() should only be called for the policy kobject at this
point if the CPU is not the last one for that policy.
Namely, if the given CPU is the last one for that policy, the
policy kobject's refcount should be 1 at this point, as set by
cpufreq_add_dev_interface(), and only needs to be dropped once for
the kobject to go away. This actually happens under the cpu == 1
check, so it need not be done before by cpufreq_cpu_put().
On the other hand, if the given CPU is not the last one for that
policy, this means that cpufreq_add_policy_cpu() has been called
at least once for that policy and cpufreq_cpu_get() has been
called for it too. To balance that cpufreq_cpu_get(), we need to
call cpufreq_cpu_put() in that case.
Thus, to fix the described problem and keep the reference
counters balanced in both cases, move the cpufreq_cpu_get() call
in __cpufreq_remove_dev() to the code path executed only for
CPUs that share the policy with other CPUs.
Reported-and-tested-by: Toralf Förster <toralf.foerster@gmx.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Cc: 3.10+ <stable@vger.kernel.org>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a4ad7339588d..f0a5e2b0eb8a 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -1177,14 +1177,11 @@ static int __cpufreq_remove_dev(struct device *dev, | |||
1177 | __func__, cpu_dev->id, cpu); | 1177 | __func__, cpu_dev->id, cpu); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | if ((cpus == 1) && (cpufreq_driver->target)) | ||
1181 | __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); | ||
1182 | |||
1183 | pr_debug("%s: removing link, cpu: %d\n", __func__, cpu); | ||
1184 | cpufreq_cpu_put(data); | ||
1185 | |||
1186 | /* If cpu is last user of policy, free policy */ | 1180 | /* If cpu is last user of policy, free policy */ |
1187 | if (cpus == 1) { | 1181 | if (cpus == 1) { |
1182 | if (cpufreq_driver->target) | ||
1183 | __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); | ||
1184 | |||
1188 | lock_policy_rwsem_read(cpu); | 1185 | lock_policy_rwsem_read(cpu); |
1189 | kobj = &data->kobj; | 1186 | kobj = &data->kobj; |
1190 | cmp = &data->kobj_unregister; | 1187 | cmp = &data->kobj_unregister; |
@@ -1205,9 +1202,13 @@ static int __cpufreq_remove_dev(struct device *dev, | |||
1205 | free_cpumask_var(data->related_cpus); | 1202 | free_cpumask_var(data->related_cpus); |
1206 | free_cpumask_var(data->cpus); | 1203 | free_cpumask_var(data->cpus); |
1207 | kfree(data); | 1204 | kfree(data); |
1208 | } else if (cpufreq_driver->target) { | 1205 | } else { |
1209 | __cpufreq_governor(data, CPUFREQ_GOV_START); | 1206 | pr_debug("%s: removing link, cpu: %d\n", __func__, cpu); |
1210 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); | 1207 | cpufreq_cpu_put(data); |
1208 | if (cpufreq_driver->target) { | ||
1209 | __cpufreq_governor(data, CPUFREQ_GOV_START); | ||
1210 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); | ||
1211 | } | ||
1211 | } | 1212 | } |
1212 | 1213 | ||
1213 | per_cpu(cpufreq_policy_cpu, cpu) = -1; | 1214 | per_cpu(cpufreq_policy_cpu, cpu) = -1; |