Skip to content

Commit

Permalink
cpufreq: Make sure target freq is within limits
Browse files Browse the repository at this point in the history
__cpufreq_driver_target() must not pass target frequency beyond the
limits of current policy.

Today most of cpufreq platform drivers are doing this check in their
target routines. Why not move it to __cpufreq_driver_target()?

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 Nov 14, 2012
1 parent 5a1c022 commit 7249924
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,12 +1470,19 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
unsigned int relation)
{
int retval = -EINVAL;
unsigned int old_target_freq = target_freq;

if (cpufreq_disabled())
return -ENODEV;

pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
target_freq, relation);
/* Make sure that target_freq is within supported range */
if (target_freq > policy->max)
target_freq = policy->max;
if (target_freq < policy->min)
target_freq = policy->min;

pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
policy->cpu, target_freq, relation, old_target_freq);

if (target_freq == policy->cur)
return 0;
Expand Down

0 comments on commit 7249924

Please sign in to comment.