cpufreq: Add and use cpufreq_for_each_{valid_,}entry_idx()
Pointer subtraction is slow and tedious. Therefore, replace all instances where cpufreq_for_each_{valid_,}entry loops contained such substractions with an iteration macro providing an index to the frequency_table entry. Suggested-by: Al Viro <viro@ZenIV.linux.org.uk> Link: http://lkml.kernel.org/r/20180120020237.GM13338@ZenIV.linux.org.uk Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:

committed by
Rafael J. Wysocki

parent
70f6bf2a3b
commit
ffd81dcfef
@@ -143,10 +143,9 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
|
||||
break;
|
||||
}
|
||||
|
||||
cpufreq_for_each_valid_entry(pos, table) {
|
||||
cpufreq_for_each_valid_entry_idx(pos, table, i) {
|
||||
freq = pos->frequency;
|
||||
|
||||
i = pos - table;
|
||||
if ((freq < policy->min) || (freq > policy->max))
|
||||
continue;
|
||||
if (freq == target_freq) {
|
||||
@@ -211,15 +210,16 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
|
||||
unsigned int freq)
|
||||
{
|
||||
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
|
||||
int idx;
|
||||
|
||||
if (unlikely(!table)) {
|
||||
pr_debug("%s: Unable to find frequency table\n", __func__);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
cpufreq_for_each_valid_entry(pos, table)
|
||||
cpufreq_for_each_valid_entry_idx(pos, table, idx)
|
||||
if (pos->frequency == freq)
|
||||
return pos - table;
|
||||
return idx;
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user