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

cpufreq: Disallow ->resolve_freq() for drivers providing ->target_index()

The handlers provided by cpufreq core are sufficient for resolving the
frequency for drivers providing ->target_index(), as the core already
has the frequency table and so ->resolve_freq() isn't required for such
platforms.

This patch disallows drivers with ->target_index() callback to use the
->resolve_freq() callback.

Also, it fixes a potential kernel crash for drivers providing ->target()
but no ->resolve_freq().

Fixes: e3c062360870 "cpufreq: add cpufreq_driver_resolve_freq()"
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
abe8bd02 5b6667c7

+12 -4
+12 -4
drivers/cpufreq/cpufreq.c
··· 507 507 { 508 508 target_freq = clamp_val(target_freq, policy->min, policy->max); 509 509 policy->cached_target_freq = target_freq; 510 + 511 + if (cpufreq_driver->target_index) { 512 + int idx; 513 + 514 + idx = cpufreq_frequency_table_target(policy, target_freq, 515 + CPUFREQ_RELATION_L); 516 + policy->cached_resolved_idx = idx; 517 + return policy->freq_table[idx].frequency; 518 + } 519 + 510 520 if (cpufreq_driver->resolve_freq) 511 521 return cpufreq_driver->resolve_freq(policy, target_freq); 512 - policy->cached_resolved_idx = 513 - cpufreq_frequency_table_target(policy, target_freq, 514 - CPUFREQ_RELATION_L); 515 - return policy->freq_table[policy->cached_resolved_idx].frequency; 522 + 523 + return target_freq; 516 524 } 517 525 518 526 /*********************************************************************