]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cpufreq: Set default policy->min/max values for all drivers
authorPierre Gondois <pierre.gondois@arm.com>
Thu, 28 May 2026 09:09:04 +0000 (11:09 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 8 Jun 2026 16:42:14 +0000 (18:42 +0200)
Some drivers set policy->min/max in their .init() callback, but
cpufreq_set_policy() will ultimately override them through:

cpufreq_policy_online()
\-cpufreq_init_policy()
  \-cpufreq_set_policy()
    \-/* Set policy->min/max */

Thus the policy min/max values set by the drivers are only temporary.

There is an exception if CPUFREQ_NEED_INITIAL_FREQ_CHECK is set and
cpufreq_policy_online() calls __cpufreq_driver_target() which invokes
cpufreq_driver->target().

To prepare for a subsequent change that will remove all initialization
of policy->min/max in driver .init() callbacks if the min/max value is
equal to the corresponding cpuinfo.min/max_freq, set default
policy->min/max values in the core for all drivers.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com>
[ rjw: Edits of the new comment and changelog ]
Link: https://patch.msgid.link/20260528090913.2759118-3-pierre.gondois@arm.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 584e4fcbf04434669a55ff8f81b27d2e7351952c..253d3ba4217cc3847049a2e458323e50e2f0259a 100644 (file)
@@ -1474,6 +1474,13 @@ static int cpufreq_policy_online(struct cpufreq_policy *policy,
                                goto out_offline_policy;
                }
 
+               /*
+                * If the driver hasn't set policy->min/max, set them as they
+                * are used for clamping frequency requests.
+                */
+               policy->min = policy->min ? policy->min : policy->cpuinfo.min_freq;
+               policy->max = policy->max ? policy->max : policy->cpuinfo.max_freq;
+
                /* related_cpus should at least include policy->cpus. */
                cpumask_copy(policy->related_cpus, policy->cpus);
        }