Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: Return index from cpufreq_frequency_table_target()

This routine can't fail unless the frequency table is invalid and
doesn't contain any valid entries.

Make it return the index and WARN() in case it is used for an invalid
table.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
d218ed77 23727845

+37 -61
+3 -4
Documentation/cpu-freq/cpu-drivers.txt
··· 245 245 246 246 int cpufreq_frequency_table_target(struct cpufreq_policy *policy, 247 247 unsigned int target_freq, 248 - unsigned int relation, 249 - unsigned int *index); 248 + unsigned int relation); 250 249 251 250 is the corresponding frequency table helper for the ->target 252 - stage. Just pass the values to this function, and the unsigned int 253 - index returns the number of the frequency table entry which contains 251 + stage. Just pass the values to this function, and this function 252 + returns the number of the frequency table entry which contains 254 253 the frequency the CPU shall be set to. 255 254 256 255 The following macros can be used as iterators over cpufreq_frequency_table:
+2 -2
drivers/cpufreq/amd_freq_sensitivity.c
··· 91 91 else { 92 92 unsigned int index; 93 93 94 - cpufreq_frequency_table_target(policy, 95 - policy->cur - 1, CPUFREQ_RELATION_H, &index); 94 + index = cpufreq_frequency_table_target(policy, 95 + policy->cur - 1, CPUFREQ_RELATION_H); 96 96 freq_next = policy->freq_table[index].frequency; 97 97 } 98 98
+2 -7
drivers/cpufreq/cpufreq.c
··· 1914 1914 unsigned int relation) 1915 1915 { 1916 1916 unsigned int old_target_freq = target_freq; 1917 - int index, retval; 1917 + int index; 1918 1918 1919 1919 if (cpufreq_disabled()) 1920 1920 return -ENODEV; ··· 1943 1943 if (!cpufreq_driver->target_index) 1944 1944 return -EINVAL; 1945 1945 1946 - retval = cpufreq_frequency_table_target(policy, target_freq, relation, 1947 - &index); 1948 - if (unlikely(retval)) { 1949 - pr_err("%s: Unable to find matching freq\n", __func__); 1950 - return retval; 1951 - } 1946 + index = cpufreq_frequency_table_target(policy, target_freq, relation); 1952 1947 1953 1948 return __target_index(policy, index); 1954 1949 }
+6 -8
drivers/cpufreq/cpufreq_ondemand.c
··· 65 65 { 66 66 unsigned int freq_req, freq_reduc, freq_avg; 67 67 unsigned int freq_hi, freq_lo; 68 - unsigned int index = 0; 68 + unsigned int index; 69 69 unsigned int delay_hi_us; 70 70 struct policy_dbs_info *policy_dbs = policy->governor_data; 71 71 struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs); ··· 79 79 return freq_next; 80 80 } 81 81 82 - cpufreq_frequency_table_target(policy, freq_next, relation, &index); 82 + index = cpufreq_frequency_table_target(policy, freq_next, relation); 83 83 freq_req = freq_table[index].frequency; 84 84 freq_reduc = freq_req * od_tuners->powersave_bias / 1000; 85 85 freq_avg = freq_req - freq_reduc; 86 86 87 87 /* Find freq bounds for freq_avg in freq_table */ 88 - index = 0; 89 - cpufreq_frequency_table_target(policy, freq_avg, CPUFREQ_RELATION_H, 90 - &index); 88 + index = cpufreq_frequency_table_target(policy, freq_avg, 89 + CPUFREQ_RELATION_H); 91 90 freq_lo = freq_table[index].frequency; 92 - index = 0; 93 - cpufreq_frequency_table_target(policy, freq_avg, CPUFREQ_RELATION_L, 94 - &index); 91 + index = cpufreq_frequency_table_target(policy, freq_avg, 92 + CPUFREQ_RELATION_L); 95 93 freq_hi = freq_table[index].frequency; 96 94 97 95 /* Find out how long we have to be in hi and lo freqs */
+13 -11
drivers/cpufreq/freq_table.c
··· 114 114 EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify); 115 115 116 116 int cpufreq_frequency_table_target(struct cpufreq_policy *policy, 117 - unsigned int target_freq, 118 - unsigned int relation, 119 - unsigned int *index) 117 + unsigned int target_freq, 118 + unsigned int relation) 120 119 { 121 120 struct cpufreq_frequency_table optimal = { 122 121 .driver_data = ~0, ··· 128 129 struct cpufreq_frequency_table *pos; 129 130 struct cpufreq_frequency_table *table = policy->freq_table; 130 131 unsigned int freq, diff, i = 0; 132 + int index; 131 133 132 134 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", 133 135 target_freq, relation, policy->cpu); ··· 192 192 } 193 193 } 194 194 if (optimal.driver_data > i) { 195 - if (suboptimal.driver_data > i) 196 - return -EINVAL; 197 - *index = suboptimal.driver_data; 195 + if (suboptimal.driver_data > i) { 196 + WARN(1, "Invalid frequency table: %d\n", policy->cpu); 197 + return 0; 198 + } 199 + 200 + index = suboptimal.driver_data; 198 201 } else 199 - *index = optimal.driver_data; 202 + index = optimal.driver_data; 200 203 201 - pr_debug("target index is %u, freq is:%u kHz\n", *index, 202 - table[*index].frequency); 203 - 204 - return 0; 204 + pr_debug("target index is %u, freq is:%u kHz\n", index, 205 + table[index].frequency); 206 + return index; 205 207 } 206 208 EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); 207 209
+2 -2
drivers/cpufreq/powernv-cpufreq.c
··· 760 760 struct cpufreq_policy policy; 761 761 762 762 cpufreq_get_policy(&policy, cpu); 763 - cpufreq_frequency_table_target(&policy, policy.cur, 764 - CPUFREQ_RELATION_C, &index); 763 + index = cpufreq_frequency_table_target(&policy, policy.cur, 764 + CPUFREQ_RELATION_C); 765 765 powernv_cpufreq_target_index(&policy, index); 766 766 cpumask_andnot(&mask, &mask, policy.cpus); 767 767 }
+6 -20
drivers/cpufreq/s3c24xx-cpufreq.c
··· 293 293 __func__, policy, target_freq, relation); 294 294 295 295 if (ftab) { 296 - if (cpufreq_frequency_table_target(policy, target_freq, 297 - relation, &index)) { 298 - s3c_freq_dbg("%s: table failed\n", __func__); 299 - return -EINVAL; 300 - } 296 + index = cpufreq_frequency_table_target(policy, target_freq, 297 + relation); 301 298 302 299 s3c_freq_dbg("%s: adjust %d to entry %d (%u)\n", __func__, 303 300 target_freq, index, ftab[index].frequency); ··· 311 314 pll = NULL; 312 315 } else { 313 316 struct cpufreq_policy tmp_policy; 314 - int ret; 315 317 316 318 /* we keep the cpu pll table in Hz, to ensure we get an 317 319 * accurate value for the PLL output. */ ··· 320 324 tmp_policy.cpu = policy->cpu; 321 325 tmp_policy.freq_table = pll_reg; 322 326 323 - /* cpufreq_frequency_table_target uses a pointer to 'index' 324 - * which is the number of the table entry, not the value of 327 + /* cpufreq_frequency_table_target returns the index 328 + * of the table entry, not the value of 325 329 * the table entry's index field. */ 326 330 327 - ret = cpufreq_frequency_table_target(&tmp_policy, target_freq, 328 - relation, &index); 329 - 330 - if (ret < 0) { 331 - pr_err("%s: no PLL available\n", __func__); 332 - goto err_notpossible; 333 - } 334 - 331 + index = cpufreq_frequency_table_target(&tmp_policy, target_freq, 332 + relation); 335 333 pll = pll_reg + index; 336 334 337 335 s3c_freq_dbg("%s: target %u => %u\n", ··· 335 345 } 336 346 337 347 return s3c_cpufreq_settarget(policy, target_freq, pll); 338 - 339 - err_notpossible: 340 - pr_err("no compatible settings for %d\n", target_freq); 341 - return -EINVAL; 342 348 } 343 349 344 350 struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
+2 -5
drivers/cpufreq/s5pv210-cpufreq.c
··· 246 246 new_freq = s5pv210_freq_table[index].frequency; 247 247 248 248 /* Finding current running level index */ 249 - if (cpufreq_frequency_table_target(policy, old_freq, CPUFREQ_RELATION_H, 250 - &priv_index)) { 251 - ret = -EINVAL; 252 - goto exit; 253 - } 249 + priv_index = cpufreq_frequency_table_target(policy, old_freq, 250 + CPUFREQ_RELATION_H); 254 251 255 252 arm_volt = dvs_conf[index].arm_volt; 256 253 int_volt = dvs_conf[index].int_volt;
+1 -2
include/linux/cpufreq.h
··· 599 599 600 600 int cpufreq_frequency_table_target(struct cpufreq_policy *policy, 601 601 unsigned int target_freq, 602 - unsigned int relation, 603 - unsigned int *index); 602 + unsigned int relation); 604 603 int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, 605 604 unsigned int freq); 606 605