Skip to content

Commit 9a1aa64

Browse files
Zihuan Zhangrafaeljw
authored andcommitted
cpufreq: Replace pointer subtraction with iteration macro
The cpufreq documentation suggests avoiding direct pointer subtraction when working with entries in driver_freq_table, as it is relatively costly. Instead, the recommended approach is to use the provided iteration macros, like cpufreq_for_each_valid_entry_idx(). Use cpufreq_for_each_entry_idx() instead of pointer subtraction in cpufreq_frequency_table_cpuinfo() which improves code clarity and follows the established cpufreq coding style. While at it, remove redundant local variable initialization from cpufreq_table_index_unsorted(). No functional change intended. Signed-off-by: Zihuan Zhang <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Subject tweak, changelog edits, local variable definition tweak ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 02d0902 commit 9a1aa64

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/cpufreq/freq_table.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy)
3333
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
3434
unsigned int min_freq = ~0;
3535
unsigned int max_freq = 0;
36-
unsigned int freq;
36+
unsigned int freq, i;
3737

38-
cpufreq_for_each_valid_entry(pos, table) {
38+
cpufreq_for_each_valid_entry_idx(pos, table, i) {
3939
freq = pos->frequency;
4040

4141
if ((!cpufreq_boost_enabled() || !policy->boost_enabled)
4242
&& (pos->flags & CPUFREQ_BOOST_FREQ))
4343
continue;
4444

45-
pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);
45+
pr_debug("table entry %u: %u kHz\n", i, freq);
4646
if (freq < min_freq)
4747
min_freq = freq;
4848
if (freq > max_freq)
@@ -126,7 +126,7 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
126126
};
127127
struct cpufreq_frequency_table *pos;
128128
struct cpufreq_frequency_table *table = policy->freq_table;
129-
unsigned int freq, diff, i = 0;
129+
unsigned int freq, diff, i;
130130
int index;
131131

132132
pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",

0 commit comments

Comments
 (0)