diff options
author | Peter Boonstoppel <pboonstoppel@nvidia.com> | 2011-08-18 11:59:58 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2011-11-30 21:48:25 -0800 |
commit | 71fd18281ec5b60e9f990d84b306700a35db68c0 (patch) | |
tree | 9af81fc72a5a2d797e493e8923e2d5fc70ca45d9 /drivers/cpufreq | |
parent | 0db59b1457ab4c9fb3efe7394aaf4544056a404a (diff) |
cpufreq: prevent out-of-bounds write when stat->last_index = -1
When cpu runs at a frequency not in cpufreq table (because of other
frequency governing mechanisms), freq_table_get_index() returns -1
which gets used as an array index.
Original-Change-Id: Id8fa5d5125c3cd1e2aad8b48ff7bd619f39c57d8
Reviewed-on: http://git-master/r/47887
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Tested-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Aleksandr Frid <afrid@nvidia.com>
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Scott Williams <scwilliams@nvidia.com>
Rebase-Id: R032fc27d227d3308e5afa17d909f64d6925e05cc
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index faf7c5217848..47885b62b247 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -59,7 +59,7 @@ static int cpufreq_stats_update(unsigned int cpu) cur_time = get_jiffies_64(); spin_lock(&cpufreq_stats_lock); stat = per_cpu(cpufreq_stats_table, cpu); - if (stat->time_in_state) + if (stat->time_in_state && stat->last_index >= 0) stat->time_in_state[stat->last_index] = cputime64_add(stat->time_in_state[stat->last_index], cputime_sub(cur_time, stat->last_time)); @@ -298,10 +298,6 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb, old_index = stat->last_index; new_index = freq_table_get_index(stat, freq->new); - /* We can't do stat->time_in_state[-1]= .. */ - if (old_index == -1 || new_index == -1) - return 0; - cpufreq_stats_update(freq->cpu); if (old_index == new_index) @@ -310,7 +306,8 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb, spin_lock(&cpufreq_stats_lock); stat->last_index = new_index; #ifdef CONFIG_CPU_FREQ_STAT_DETAILS - stat->trans_table[old_index * stat->max_state + new_index]++; + if (old_index >= 0 && new_index >= 0) + stat->trans_table[old_index * stat->max_state + new_index]++; #endif stat->total_trans++; spin_unlock(&cpufreq_stats_lock); |