diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 3196cb61b91fe..56c6c4fed9cc5 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -577,11 +577,12 @@ static void cpufreq_powerstats_free(void) } static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, - int cpu, struct cpufreq_frequency_table *table, int count) + struct cpufreq_frequency_table *table, int count) { unsigned int i, ret = 0; struct cpufreq_stats *stat; unsigned int alloc_size; + unsigned int cpu = policy->cpu; struct cpufreq_frequency_table *pos; if (per_cpu(cpufreq_stats_table, cpu)) @@ -591,6 +592,8 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, return -ENOMEM; ret = sysfs_create_group(&policy->kobj, &stats_attr_group); + if (ret) + goto error_out; stat->cpu = cpu; per_cpu(cpufreq_stats_table, cpu) = stat; @@ -623,6 +626,7 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, return 0; error_alloc: sysfs_remove_group(&policy->kobj, &stats_attr_group); +error_out: kfree(stat); per_cpu(cpufreq_stats_table, cpu) = NULL; return ret; @@ -801,7 +805,7 @@ static void cpufreq_stats_create_table(unsigned int cpu) if (!per_cpu(cpufreq_power_stats, cpu)) cpufreq_powerstats_create(cpu, table, count); - __cpufreq_stats_create_table(policy, cpu, table, count); + __cpufreq_stats_create_table(policy, table, count); } cpufreq_cpu_put(policy); } @@ -859,7 +863,7 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb, } if (val == CPUFREQ_CREATE_POLICY) - ret = __cpufreq_stats_create_table(policy, cpu, table, count); + ret = __cpufreq_stats_create_table(policy, table, count); return ret; }