Commit 3c84ef3a authored by Stratos Karafotis's avatar Stratos Karafotis Committed by Rafael J. Wysocki

thermal: cpu_cooling: Use cpufreq_for_each_valid_entry macro for iteration

The cpufreq core now supports the cpufreq_for_each_valid_entry macro
helper for iteration over the cpufreq_frequency_table, so use it.

Also remove the redundant !! operator.

It should have no functional changes.
Signed-off-by: default avatarStratos Karafotis <stratosk@semaphore.gr>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 4966ee40
...@@ -144,11 +144,11 @@ static int get_property(unsigned int cpu, unsigned long input, ...@@ -144,11 +144,11 @@ static int get_property(unsigned int cpu, unsigned long input,
unsigned int *output, unsigned int *output,
enum cpufreq_cooling_property property) enum cpufreq_cooling_property property)
{ {
int i, j; int i;
unsigned long max_level = 0, level = 0; unsigned long max_level = 0, level = 0;
unsigned int freq = CPUFREQ_ENTRY_INVALID; unsigned int freq = CPUFREQ_ENTRY_INVALID;
int descend = -1; int descend = -1;
struct cpufreq_frequency_table *table = struct cpufreq_frequency_table *pos, *table =
cpufreq_frequency_get_table(cpu); cpufreq_frequency_get_table(cpu);
if (!output) if (!output)
...@@ -157,20 +157,16 @@ static int get_property(unsigned int cpu, unsigned long input, ...@@ -157,20 +157,16 @@ static int get_property(unsigned int cpu, unsigned long input,
if (!table) if (!table)
return -EINVAL; return -EINVAL;
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { cpufreq_for_each_valid_entry(pos, table) {
/* ignore invalid entries */
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
/* ignore duplicate entry */ /* ignore duplicate entry */
if (freq == table[i].frequency) if (freq == pos->frequency)
continue; continue;
/* get the frequency order */ /* get the frequency order */
if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
descend = !!(freq > table[i].frequency); descend = freq > pos->frequency;
freq = table[i].frequency; freq = pos->frequency;
max_level++; max_level++;
} }
...@@ -190,29 +186,26 @@ static int get_property(unsigned int cpu, unsigned long input, ...@@ -190,29 +186,26 @@ static int get_property(unsigned int cpu, unsigned long input,
if (property == GET_FREQ) if (property == GET_FREQ)
level = descend ? input : (max_level - input); level = descend ? input : (max_level - input);
for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { i = 0;
/* ignore invalid entry */ cpufreq_for_each_valid_entry(pos, table) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
continue;
/* ignore duplicate entry */ /* ignore duplicate entry */
if (freq == table[i].frequency) if (freq == pos->frequency)
continue; continue;
/* now we have a valid frequency entry */ /* now we have a valid frequency entry */
freq = table[i].frequency; freq = pos->frequency;
if (property == GET_LEVEL && (unsigned int)input == freq) { if (property == GET_LEVEL && (unsigned int)input == freq) {
/* get level by frequency */ /* get level by frequency */
*output = descend ? j : (max_level - j); *output = descend ? i : (max_level - i);
return 0; return 0;
} }
if (property == GET_FREQ && level == j) { if (property == GET_FREQ && level == i) {
/* get frequency by level */ /* get frequency by level */
*output = freq; *output = freq;
return 0; return 0;
} }
j++; i++;
} }
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment