cpufreq: Avoid calling cpufreq_verify_current_freq() from handle_update()
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 20 Jun 2019 03:05:50 +0000 (08:35 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Jun 2019 09:24:56 +0000 (11:24 +0200)
On some occasions cpufreq_verify_current_freq() schedules a work whose
callback is handle_update(), which further calls cpufreq_update_policy()
which may end up calling cpufreq_verify_current_freq() again.

On the other hand, when cpufreq_update_policy() is called from
handle_update(), the pointer to the cpufreq policy is already
available, but cpufreq_cpu_acquire() is still called to get it in
cpufreq_update_policy(), which should be avoided as well.

To fix these issues, create a new helper, refresh_frequency_limits(),
and make both handle_update() call it cpufreq_update_policy().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Rename reeval_frequency_limits() as refresh_frequency_limits() ]
[ rjw: Changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index cba9c9e1bd0f3bf73f437dba04397b8cdfc59ed3..ceb57af15ca083b42f7eaddd5b03522e109b6abb 100644 (file)
@@ -1115,13 +1115,25 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
        return ret;
 }
 
+static void refresh_frequency_limits(struct cpufreq_policy *policy)
+{
+       struct cpufreq_policy new_policy = *policy;
+
+       pr_debug("updating policy for CPU %u\n", policy->cpu);
+
+       new_policy.min = policy->user_policy.min;
+       new_policy.max = policy->user_policy.max;
+
+       cpufreq_set_policy(policy, &new_policy);
+}
+
 static void handle_update(struct work_struct *work)
 {
        struct cpufreq_policy *policy =
                container_of(work, struct cpufreq_policy, update);
-       unsigned int cpu = policy->cpu;
-       pr_debug("handle_update for cpu %u called\n", cpu);
-       cpufreq_update_policy(cpu);
+
+       pr_debug("handle_update for cpu %u called\n", policy->cpu);
+       refresh_frequency_limits(policy);
 }
 
 static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
@@ -2376,7 +2388,6 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
 void cpufreq_update_policy(unsigned int cpu)
 {
        struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
-       struct cpufreq_policy new_policy;
 
        if (!policy)
                return;
@@ -2389,12 +2400,7 @@ void cpufreq_update_policy(unsigned int cpu)
            (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
                goto unlock;
 
-       pr_debug("updating policy for CPU %u\n", cpu);
-       memcpy(&new_policy, policy, sizeof(*policy));
-       new_policy.min = policy->user_policy.min;
-       new_policy.max = policy->user_policy.max;
-
-       cpufreq_set_policy(policy, &new_policy);
+       refresh_frequency_limits(policy);
 
 unlock:
        cpufreq_cpu_release(policy);