Skip to content

Commit

Permalink
cpufreq: Disallow ->resolve_freq() for drivers providing ->target_ind…
Browse files Browse the repository at this point in the history
…ex()

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: e3c0623 "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>
  • Loading branch information
Viresh Kumar authored and Rafael J. Wysocki committed Jul 21, 2016
1 parent 5b6667c commit abe8bd0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,20 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
{
target_freq = clamp_val(target_freq, policy->min, policy->max);
policy->cached_target_freq = target_freq;

if (cpufreq_driver->target_index) {
int idx;

idx = cpufreq_frequency_table_target(policy, target_freq,
CPUFREQ_RELATION_L);
policy->cached_resolved_idx = idx;
return policy->freq_table[idx].frequency;
}

if (cpufreq_driver->resolve_freq)
return cpufreq_driver->resolve_freq(policy, target_freq);
policy->cached_resolved_idx =
cpufreq_frequency_table_target(policy, target_freq,
CPUFREQ_RELATION_L);
return policy->freq_table[policy->cached_resolved_idx].frequency;

return target_freq;
}

/*********************************************************************
Expand Down

0 comments on commit abe8bd0

Please sign in to comment.