* [RFC] cpufreq: Make sure target freq is within limits
@ 2012-10-25 6:33 Viresh Kumar
2012-10-26 11:23 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Viresh Kumar @ 2012-10-25 6:33 UTC (permalink / raw)
To: rjw
Cc: cpufreq, linux-pm, linux-kernel, linux-arm-kernel, linaro-dev,
patches, pdsw-power-team, arvind.chauhan, Viresh Kumar
Hi Rafael,
__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().
I wanted to get your opinion on this before making changes in all driver files.
That's why this is an RFC.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f552d5f..59264f1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -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 (cpu_online(policy->cpu) && cpufreq_driver->target)
retval = cpufreq_driver->target(policy, target_freq, relation);
--
1.7.12.rc2.18.g61b472e
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC] cpufreq: Make sure target freq is within limits
2012-10-25 6:33 [RFC] cpufreq: Make sure target freq is within limits Viresh Kumar
@ 2012-10-26 11:23 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2012-10-26 11:23 UTC (permalink / raw)
To: Viresh Kumar
Cc: cpufreq, linux-pm, linux-kernel, linux-arm-kernel, linaro-dev,
patches, pdsw-power-team, arvind.chauhan
On Thursday, October 25, 2012 12:03:34 PM Viresh Kumar wrote:
> Hi Rafael,
>
> __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().
>
> I wanted to get your opinion on this before making changes in all driver files.
> That's why this is an RFC.
I'd prefer to apply the patch below before changing the drviers.
Thanks,
Rafael
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> drivers/cpufreq/cpufreq.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index f552d5f..59264f1 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -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 (cpu_online(policy->cpu) && cpufreq_driver->target)
> retval = cpufreq_driver->target(policy, target_freq, relation);
>
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-26 11:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-25 6:33 [RFC] cpufreq: Make sure target freq is within limits Viresh Kumar
2012-10-26 11:23 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).