cpufreq: Warn users while freeing active policy
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 7 Jul 2022 09:58:31 +0000 (15:28 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 15 Jul 2022 17:19:51 +0000 (19:19 +0200)
With the new design in place, the show() and store() callbacks check if
the policy is active or not before proceeding any further to avoid
potential races. And in order to guarantee that cpufreq_policy_free()
must be called after clearing the policy->cpus mask, i.e. by marking the
policy inactive.

In order to avoid introducing a bug around this later, print a warning
message if we end up freeing an active policy.

Also update cpufreq_online() a bit to make sure we clear the cpus mask
for each error case before calling cpufreq_policy_free().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 73432360e6e98424cc208fe924534f200a4da931..954eef26685f1e83addefdd66f6fb2bd6e4cae3f 100644 (file)
@@ -1273,6 +1273,13 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
        unsigned long flags;
        int cpu;
 
+       /*
+        * The callers must ensure the policy is inactive by now, to avoid any
+        * races with show()/store() callbacks.
+        */
+       if (unlikely(!policy_is_inactive(policy)))
+               pr_warn("%s: Freeing active policy\n", __func__);
+
        /* Remove policy from list */
        write_lock_irqsave(&cpufreq_driver_lock, flags);
        list_del(&policy->policy_list);
@@ -1527,8 +1534,6 @@ out_destroy_policy:
        for_each_cpu(j, policy->real_cpus)
                remove_cpu_dev_symlink(policy, j, get_cpu_device(j));
 
-       cpumask_clear(policy->cpus);
-
 out_offline_policy:
        if (cpufreq_driver->offline)
                cpufreq_driver->offline(policy);
@@ -1538,6 +1543,7 @@ out_exit_policy:
                cpufreq_driver->exit(policy);
 
 out_free_policy:
+       cpumask_clear(policy->cpus);
        up_write(&policy->rwsem);
 
        cpufreq_policy_free(policy);