aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStratos Karafotis <stratosk@semaphore.gr>2014-04-25 16:16:39 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-29 18:06:49 -0400
commit3c84ef3af7c5778e25145a1fef29a816730a830c (patch)
treee34122e0e7738c331ed69de13a4df0f51303f3aa
parent4966ee4037fedd80871659333172481073ec2fac (diff)
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: Stratos Karafotis <stratosk@semaphore.gr> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/thermal/cpu_cooling.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262c4bd2..84a75f89bf74 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -144,11 +144,11 @@ static int get_property(unsigned int cpu, unsigned long input,
144 unsigned int *output, 144 unsigned int *output,
145 enum cpufreq_cooling_property property) 145 enum cpufreq_cooling_property property)
146{ 146{
147 int i, j; 147 int i;
148 unsigned long max_level = 0, level = 0; 148 unsigned long max_level = 0, level = 0;
149 unsigned int freq = CPUFREQ_ENTRY_INVALID; 149 unsigned int freq = CPUFREQ_ENTRY_INVALID;
150 int descend = -1; 150 int descend = -1;
151 struct cpufreq_frequency_table *table = 151 struct cpufreq_frequency_table *pos, *table =
152 cpufreq_frequency_get_table(cpu); 152 cpufreq_frequency_get_table(cpu);
153 153
154 if (!output) 154 if (!output)
@@ -157,20 +157,16 @@ static int get_property(unsigned int cpu, unsigned long input,
157 if (!table) 157 if (!table)
158 return -EINVAL; 158 return -EINVAL;
159 159
160 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 160 cpufreq_for_each_valid_entry(pos, table) {
161 /* ignore invalid entries */
162 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
163 continue;
164
165 /* ignore duplicate entry */ 161 /* ignore duplicate entry */
166 if (freq == table[i].frequency) 162 if (freq == pos->frequency)
167 continue; 163 continue;
168 164
169 /* get the frequency order */ 165 /* get the frequency order */
170 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) 166 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
171 descend = !!(freq > table[i].frequency); 167 descend = freq > pos->frequency;
172 168
173 freq = table[i].frequency; 169 freq = pos->frequency;
174 max_level++; 170 max_level++;
175 } 171 }
176 172
@@ -190,29 +186,26 @@ static int get_property(unsigned int cpu, unsigned long input,
190 if (property == GET_FREQ) 186 if (property == GET_FREQ)
191 level = descend ? input : (max_level - input); 187 level = descend ? input : (max_level - input);
192 188
193 for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 189 i = 0;
194 /* ignore invalid entry */ 190 cpufreq_for_each_valid_entry(pos, table) {
195 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
196 continue;
197
198 /* ignore duplicate entry */ 191 /* ignore duplicate entry */
199 if (freq == table[i].frequency) 192 if (freq == pos->frequency)
200 continue; 193 continue;
201 194
202 /* now we have a valid frequency entry */ 195 /* now we have a valid frequency entry */
203 freq = table[i].frequency; 196 freq = pos->frequency;
204 197
205 if (property == GET_LEVEL && (unsigned int)input == freq) { 198 if (property == GET_LEVEL && (unsigned int)input == freq) {
206 /* get level by frequency */ 199 /* get level by frequency */
207 *output = descend ? j : (max_level - j); 200 *output = descend ? i : (max_level - i);
208 return 0; 201 return 0;
209 } 202 }
210 if (property == GET_FREQ && level == j) { 203 if (property == GET_FREQ && level == i) {
211 /* get frequency by level */ 204 /* get frequency by level */
212 *output = freq; 205 *output = freq;
213 return 0; 206 return 0;
214 } 207 }
215 j++; 208 i++;
216 } 209 }
217 210
218 return -EINVAL; 211 return -EINVAL;