Skip to content

Commit

Permalink
cpufreq: Prevent memory leak in cpufreq_stats on hotplug
Browse files Browse the repository at this point in the history
Ensures that cpufreq_stats_free_table is called before
__cpufreq_remove_dev on cpu hotplug (which also occurs during
suspend on SMP systems) to make sure that sysfs_remove_group
can get called before the cpufreq kobj is freed.  Otherwise,
the sysfs file structures are leaked.

Change-Id: I87e55277272f5cfad47e9e7c92630e990bb90069
Signed-off-by: Colin Cross <ccross@android.com>
(cherry picked from commit 094ea9f2b10e36fe2935333774cab69d6fea8bc4)

Signed-off-by: nobodyAtall <tsogkas@ceid.upatras.gr>
Signed-off-by: garwedgess <garethwilliams21@gmail.com>
  • Loading branch information
arco authored and garwedgess committed Jun 11, 2013
1 parent 8355387 commit 181d041
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions drivers/cpufreq/cpufreq_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,27 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
return 0;
}

static int cpufreq_stats_create_table_cpu(unsigned int cpu)
{
struct cpufreq_policy *policy;
struct cpufreq_frequency_table *table;
int ret = -ENODEV;

policy = cpufreq_cpu_get(cpu);
if (!policy)
return -ENODEV;

table = cpufreq_frequency_get_table(cpu);
if (!table)
goto out;

ret = cpufreq_stats_create_table(policy, table);

out:
cpufreq_cpu_put(policy);
return ret;
}

static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
unsigned long action,
void *hcpu)
Expand All @@ -315,17 +336,22 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
case CPU_ONLINE_FROZEN:
cpufreq_update_policy(cpu);
break;
case CPU_DEAD:
case CPU_DEAD_FROZEN:
case CPU_DOWN_PREPARE:
case CPU_DOWN_PREPARE_FROZEN:
cpufreq_stats_free_table(cpu);
break;
case CPU_DOWN_FAILED:
case CPU_DOWN_FAILED_FROZEN:
cpufreq_stats_create_table_cpu(cpu);
break;
}
return NOTIFY_OK;
}

static struct notifier_block cpufreq_stat_cpu_notifier __refdata =
{
.notifier_call = cpufreq_stat_cpu_callback,
.priority = 1,
};

static struct notifier_block notifier_policy_block = {
Expand Down

0 comments on commit 181d041

Please sign in to comment.