Skip to content

Commit c5746dc

Browse files
Zihuan Zhangrafaeljw
authored andcommitted
cpufreq: Avoid calling get_governor() for first policy
When a cpufreq driver registers the first policy, it may attempt to initialize the policy governor from `last_governor`. However, this is meaningless for the first policy instance, because `last_governor` is only updated when policies are removed (e.g. during CPU offline). The `last_governor` mechanism is intended to restore the previously used governor across CPU hotplug events. For the very first policy, there is no "previous governor" to restore, so calling get_governor(last_governor) is unnecessary and potentially confusing. Skip looking up `last_governor` when registering the first policy. Instead, it directly uses the default governor after all governors have been registered and are available. This avoids meaningless lookups, reduces unnecessary module reference handling, and simplifies the initial policy path. Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Lifeng Zheng <zhenglifeng1@huawei.com> Link: https://patch.msgid.link/20250725041450.68754-1-zhangzihuan@kylinos.cn [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent c17b750 commit c5746dc

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,8 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
11211121

11221122
if (has_target()) {
11231123
/* Update policy governor to the one used before hotplug. */
1124-
gov = get_governor(policy->last_governor);
1124+
if (policy->last_governor[0] != '\0')
1125+
gov = get_governor(policy->last_governor);
11251126
if (gov) {
11261127
pr_debug("Restoring governor %s for cpu %d\n",
11271128
gov->name, policy->cpu);

0 commit comments

Comments
 (0)