cpufreq: Drop redundant check from cpufreq_update_current_freq()
[cascardo/linux.git] / drivers / cpufreq / cpufreq.c
index cc252ee..118b4f3 100644 (file)
@@ -1544,9 +1544,6 @@ static unsigned int cpufreq_update_current_freq(struct cpufreq_policy *policy)
 {
        unsigned int new_freq;
 
-       if (cpufreq_suspended)
-               return 0;
-
        new_freq = cpufreq_driver->get(policy->cpu);
        if (!new_freq)
                return 0;
@@ -1820,7 +1817,7 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier);
 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
                                        unsigned int target_freq)
 {
-       clamp_val(target_freq, policy->min, policy->max);
+       target_freq = clamp_val(target_freq, policy->min, policy->max);
 
        return cpufreq_driver->fast_switch(policy, target_freq);
 }
@@ -1852,14 +1849,17 @@ static int __target_intermediate(struct cpufreq_policy *policy,
        return ret;
 }
 
-static int __target_index(struct cpufreq_policy *policy,
-                         struct cpufreq_frequency_table *freq_table, int index)
+static int __target_index(struct cpufreq_policy *policy, int index)
 {
        struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
        unsigned int intermediate_freq = 0;
+       unsigned int newfreq = policy->freq_table[index].frequency;
        int retval = -EINVAL;
        bool notify;
 
+       if (newfreq == policy->cur)
+               return 0;
+
        notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);
        if (notify) {
                /* Handle switching to intermediate frequency */
@@ -1874,7 +1874,7 @@ static int __target_index(struct cpufreq_policy *policy,
                                freqs.old = freqs.new;
                }
 
-               freqs.new = freq_table[index].frequency;
+               freqs.new = newfreq;
                pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
                         __func__, policy->cpu, freqs.old, freqs.new);
 
@@ -1911,8 +1911,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
                            unsigned int relation)
 {
        unsigned int old_target_freq = target_freq;
-       struct cpufreq_frequency_table *freq_table;
-       int index, retval;
+       int index;
 
        if (cpufreq_disabled())
                return -ENODEV;
@@ -1941,23 +1940,9 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
        if (!cpufreq_driver->target_index)
                return -EINVAL;
 
-       freq_table = policy->freq_table;
-       if (unlikely(!freq_table)) {
-               pr_err("%s: Unable to find freq_table\n", __func__);
-               return -EINVAL;
-       }
-
-       retval = cpufreq_frequency_table_target(policy, freq_table, target_freq,
-                                               relation, &index);
-       if (unlikely(retval)) {
-               pr_err("%s: Unable to find matching freq\n", __func__);
-               return retval;
-       }
+       index = cpufreq_frequency_table_target(policy, target_freq, relation);
 
-       if (freq_table[index].frequency == policy->cur)
-               return 0;
-
-       return __target_index(policy, freq_table, index);
+       return __target_index(policy, index);
 }
 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
 
@@ -2292,6 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
         * -> ask driver for current freq and notify governors about a change
         */
        if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
+               if (cpufreq_suspended) {
+                       ret = -EAGAIN;
+                       goto unlock;
+               }
                new_policy.cur = cpufreq_update_current_freq(policy);
                if (WARN_ON(!new_policy.cur)) {
                        ret = -EIO;