Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98aa9f47 authored by Junjie Wu's avatar Junjie Wu
Browse files

cpufreq: Fix restore of policy min/max for hotplug



Commit fdfdc36e
("cpufreq: Save and restore user min/max freq for hotplug") only
partially achieved what it intended due to wrong placement of policy
restore code.

While policy->user_policy.min/max are restored correctly, new_policy
min/max have copied initial policy->min/max instead of
restored ones. cpufreq_set_policy() overwrites restored policy->min/max
after setting the frequency, resulting in a policy->min/max range that
potentially violates the one specified by policy->user_policy. The
error will persist until next time cpufreq_update_policy() is called.

Fix by moving policy min/max restore before copying current policy to
new_policy.

Change-Id: Ib97500d26fcd98dc23d26456c699abfeaa9a9c07
Signed-off-by: default avatarJunjie Wu <junjiew@codeaurora.org>
parent fa3dfef9
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -980,6 +980,18 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
	struct cpufreq_policy new_policy;
	int ret = 0;

	/* Restore policy->min/max for hotplug */
	if (per_cpu(cpufreq_policy_save, policy->cpu).min) {
		policy->min = per_cpu(cpufreq_policy_save, policy->cpu).min;
		policy->user_policy.min = policy->min;
	}
	if (per_cpu(cpufreq_policy_save, policy->cpu).max) {
		policy->max = per_cpu(cpufreq_policy_save, policy->cpu).max;
		policy->user_policy.max = policy->max;
	}
	pr_debug("Restoring CPU%d user policy min %d and max %d\n",
		 policy->cpu, policy->min, policy->max);

	memcpy(&new_policy, policy, sizeof(*policy));

	/* Update governor of new_policy to the governor used before hotplug */
@@ -992,17 +1004,6 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)

	new_policy.governor = gov;

	if (per_cpu(cpufreq_policy_save, policy->cpu).min) {
		policy->min = per_cpu(cpufreq_policy_save, policy->cpu).min;
		policy->user_policy.min = policy->min;
	}
	if (per_cpu(cpufreq_policy_save, policy->cpu).max) {
		policy->max = per_cpu(cpufreq_policy_save, policy->cpu).max;
		policy->user_policy.max = policy->max;
	}
	pr_debug("Restoring CPU%d user policy min %d and max %d\n",
		 policy->cpu, policy->min, policy->max);

	/* Use the default policy if its valid. */
	if (cpufreq_driver->setpolicy)
		cpufreq_parse_governor(gov->name, &new_policy.policy, NULL);