diff options
| author | Viresh Kumar <viresh.kumar@linaro.org> | 2014-01-06 20:40:12 -0500 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-01-16 20:00:44 -0500 |
| commit | 2d13594dcb7eaa41fa180e8a3b27a8f10845381f (patch) | |
| tree | 332e3cdd241084135283e4658a7fa98a95404b77 | |
| parent | 027cc2e4a6127fdf29e17a422aacb5ecd9830cbb (diff) | |
cpufreq: stats: free table and remove sysfs entry in a single routine
We don't have code paths now where we need to do these two things
separately, so it is better do them in a single routine. Just as
they are allocated in a single routine.
Acked-by: Nicolas Pitre <nico@linaro.org>
Tested-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
| -rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 8fa58440ea95..9dd58835456e 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
| @@ -151,40 +151,32 @@ static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) | |||
| 151 | return -1; | 151 | return -1; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | /* should be called late in the CPU removal sequence so that the stats | 154 | static void __cpufreq_stats_free_table(struct cpufreq_policy *policy) |
| 155 | * memory is still available in case someone tries to use it. | ||
| 156 | */ | ||
| 157 | static void cpufreq_stats_free_table(unsigned int cpu) | ||
| 158 | { | 155 | { |
| 159 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu); | 156 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu); |
| 160 | 157 | ||
| 161 | if (stat) { | 158 | if (!stat) |
| 162 | pr_debug("%s: Free stat table\n", __func__); | 159 | return; |
| 163 | kfree(stat->time_in_state); | 160 | |
| 164 | kfree(stat); | 161 | pr_debug("%s: Free stat table\n", __func__); |
| 165 | per_cpu(cpufreq_stats_table, cpu) = NULL; | 162 | |
| 166 | } | 163 | sysfs_remove_group(&policy->kobj, &stats_attr_group); |
| 164 | kfree(stat->time_in_state); | ||
| 165 | kfree(stat); | ||
| 166 | per_cpu(cpufreq_stats_table, policy->cpu) = NULL; | ||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | /* must be called early in the CPU removal sequence (before | 169 | static void cpufreq_stats_free_table(unsigned int cpu) |
| 170 | * cpufreq_remove_dev) so that policy is still valid. | ||
| 171 | */ | ||
| 172 | static void cpufreq_stats_free_sysfs(unsigned int cpu) | ||
| 173 | { | 170 | { |
| 174 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | 171 | struct cpufreq_policy *policy; |
| 175 | 172 | ||
| 173 | policy = cpufreq_cpu_get(cpu); | ||
| 176 | if (!policy) | 174 | if (!policy) |
| 177 | return; | 175 | return; |
| 178 | 176 | ||
| 179 | if (!cpufreq_frequency_get_table(cpu)) | 177 | if (cpufreq_frequency_get_table(policy->cpu)) |
| 180 | goto put_ref; | 178 | __cpufreq_stats_free_table(policy); |
| 181 | |||
| 182 | if (!policy_is_shared(policy)) { | ||
| 183 | pr_debug("%s: Free sysfs stat\n", __func__); | ||
| 184 | sysfs_remove_group(&policy->kobj, &stats_attr_group); | ||
| 185 | } | ||
| 186 | 179 | ||
| 187 | put_ref: | ||
| 188 | cpufreq_cpu_put(policy); | 180 | cpufreq_cpu_put(policy); |
| 189 | } | 181 | } |
| 190 | 182 | ||
| @@ -293,10 +285,8 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb, | |||
| 293 | 285 | ||
| 294 | if (val == CPUFREQ_CREATE_POLICY) | 286 | if (val == CPUFREQ_CREATE_POLICY) |
| 295 | ret = cpufreq_stats_create_table(policy, table); | 287 | ret = cpufreq_stats_create_table(policy, table); |
| 296 | else if (val == CPUFREQ_REMOVE_POLICY) { | 288 | else if (val == CPUFREQ_REMOVE_POLICY) |
| 297 | cpufreq_stats_free_sysfs(cpu); | 289 | __cpufreq_stats_free_table(policy); |
| 298 | cpufreq_stats_free_table(cpu); | ||
| 299 | } | ||
| 300 | 290 | ||
| 301 | return ret; | 291 | return ret; |
| 302 | } | 292 | } |
| @@ -376,10 +366,8 @@ static void __exit cpufreq_stats_exit(void) | |||
| 376 | CPUFREQ_POLICY_NOTIFIER); | 366 | CPUFREQ_POLICY_NOTIFIER); |
| 377 | cpufreq_unregister_notifier(¬ifier_trans_block, | 367 | cpufreq_unregister_notifier(¬ifier_trans_block, |
| 378 | CPUFREQ_TRANSITION_NOTIFIER); | 368 | CPUFREQ_TRANSITION_NOTIFIER); |
| 379 | for_each_online_cpu(cpu) { | 369 | for_each_online_cpu(cpu) |
| 380 | cpufreq_stats_free_table(cpu); | 370 | cpufreq_stats_free_table(cpu); |
| 381 | cpufreq_stats_free_sysfs(cpu); | ||
| 382 | } | ||
| 383 | } | 371 | } |
| 384 | 372 | ||
| 385 | MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>"); | 373 | MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>"); |
