--- zzzz-none-000/linux-4.4.271/drivers/cpufreq/cpufreq_stats.c 2021-06-03 06:22:09.000000000 +0000 +++ dakota-7530ac-750/linux-4.4.271/drivers/cpufreq/cpufreq_stats.c 2023-01-11 09:25:41.000000000 +0000 @@ -14,6 +14,7 @@ #include #include #include +#include static spinlock_t cpufreq_stats_lock; @@ -22,7 +23,7 @@ unsigned long long last_time; unsigned int max_state; unsigned int state_num; - unsigned int last_index; + int last_index; u64 *time_in_state; unsigned int *freq_table; #ifdef CONFIG_CPU_FREQ_STAT_DETAILS @@ -68,6 +69,8 @@ ssize_t len = 0; int i, j; + cpufreq_stats_update(stats); + len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); len += snprintf(buf + len, PAGE_SIZE - len, " : "); for (i = 0; i < stats->state_num; i++) { @@ -190,10 +193,11 @@ alloc_size += count * count * sizeof(int); #endif - /* Allocate memory for time_in_state/freq_table/trans_table in one go */ stats->time_in_state = kzalloc(alloc_size, GFP_KERNEL); - if (!stats->time_in_state) + if (!stats->time_in_state) { + ret = -ENOMEM; goto free_stat; + } stats->freq_table = (unsigned int *)(stats->time_in_state + count); @@ -283,10 +287,6 @@ old_index = stats->last_index; new_index = freq_table_get_index(stats, freq->new); - /* We can't do stats->time_in_state[-1]= .. */ - if (old_index == -1 || new_index == -1) - goto put_policy; - if (old_index == new_index) goto put_policy; @@ -294,7 +294,10 @@ stats->last_index = new_index; #ifdef CONFIG_CPU_FREQ_STAT_DETAILS - stats->trans_table[old_index * stats->max_state + new_index]++; + /* From old_index ... to new_index */ + if (old_index >= 0 && new_index >= 0) { + stats->trans_table[old_index * stats->max_state + new_index]++; + } #endif stats->total_trans++;