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>
This commit is contained in:
parent
027cc2e4a6
commit
2d13594dcb
1 changed files with 19 additions and 31 deletions
|
@ -151,40 +151,32 @@ static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* should be called late in the CPU removal sequence so that the stats
|
static void __cpufreq_stats_free_table(struct cpufreq_policy *policy)
|
||||||
* memory is still available in case someone tries to use it.
|
|
||||||
*/
|
|
||||||
static void cpufreq_stats_free_table(unsigned int cpu)
|
|
||||||
{
|
{
|
||||||
struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
|
struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
|
||||||
|
|
||||||
if (stat) {
|
if (!stat)
|
||||||
pr_debug("%s: Free stat table\n", __func__);
|
return;
|
||||||
kfree(stat->time_in_state);
|
|
||||||
kfree(stat);
|
pr_debug("%s: Free stat table\n", __func__);
|
||||||
per_cpu(cpufreq_stats_table, cpu) = NULL;
|
|
||||||
}
|
sysfs_remove_group(&policy->kobj, &stats_attr_group);
|
||||||
|
kfree(stat->time_in_state);
|
||||||
|
kfree(stat);
|
||||||
|
per_cpu(cpufreq_stats_table, policy->cpu) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must be called early in the CPU removal sequence (before
|
static void cpufreq_stats_free_table(unsigned int cpu)
|
||||||
* cpufreq_remove_dev) so that policy is still valid.
|
|
||||||
*/
|
|
||||||
static void cpufreq_stats_free_sysfs(unsigned int cpu)
|
|
||||||
{
|
{
|
||||||
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
|
struct cpufreq_policy *policy;
|
||||||
|
|
||||||
|
policy = cpufreq_cpu_get(cpu);
|
||||||
if (!policy)
|
if (!policy)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!cpufreq_frequency_get_table(cpu))
|
if (cpufreq_frequency_get_table(policy->cpu))
|
||||||
goto put_ref;
|
__cpufreq_stats_free_table(policy);
|
||||||
|
|
||||||
if (!policy_is_shared(policy)) {
|
|
||||||
pr_debug("%s: Free sysfs stat\n", __func__);
|
|
||||||
sysfs_remove_group(&policy->kobj, &stats_attr_group);
|
|
||||||
}
|
|
||||||
|
|
||||||
put_ref:
|
|
||||||
cpufreq_cpu_put(policy);
|
cpufreq_cpu_put(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,10 +285,8 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
|
||||||
|
|
||||||
if (val == CPUFREQ_CREATE_POLICY)
|
if (val == CPUFREQ_CREATE_POLICY)
|
||||||
ret = cpufreq_stats_create_table(policy, table);
|
ret = cpufreq_stats_create_table(policy, table);
|
||||||
else if (val == CPUFREQ_REMOVE_POLICY) {
|
else if (val == CPUFREQ_REMOVE_POLICY)
|
||||||
cpufreq_stats_free_sysfs(cpu);
|
__cpufreq_stats_free_table(policy);
|
||||||
cpufreq_stats_free_table(cpu);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -376,10 +366,8 @@ static void __exit cpufreq_stats_exit(void)
|
||||||
CPUFREQ_POLICY_NOTIFIER);
|
CPUFREQ_POLICY_NOTIFIER);
|
||||||
cpufreq_unregister_notifier(¬ifier_trans_block,
|
cpufreq_unregister_notifier(¬ifier_trans_block,
|
||||||
CPUFREQ_TRANSITION_NOTIFIER);
|
CPUFREQ_TRANSITION_NOTIFIER);
|
||||||
for_each_online_cpu(cpu) {
|
for_each_online_cpu(cpu)
|
||||||
cpufreq_stats_free_table(cpu);
|
cpufreq_stats_free_table(cpu);
|
||||||
cpufreq_stats_free_sysfs(cpu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>");
|
MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>");
|
||||||
|
|
Loading…
Reference in a new issue