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

Commit cb99ab45 authored by Taniya Das's avatar Taniya Das Committed by Rohit Gupta
Browse files

cpufreq: Reject improper settings for userspace min/max limits



When userspace min/max limits are written to they are compared against
the aggregated max/min respectively. This can take system to a bad
state as follows:
1) Userspace client writes a max value that is lower than the
   original value.
2) A kernel client happens to hold a vote for max higher than the
   userspace max value, so that is what the policy->max is set to
   as part of cpufreq_set_policy(). But we still set user_policy->max
   to the value from step 1.
3) Userspace writes a min value that is higher than the max value it
   wrote before (in step 1). Since cpufreq_set_policy() compares it
   against policy->max the write is successful and user_policy->min
   is now higher than user_policy->max.
If all the CPUs in a policy go offline with this bad state, trying
to bring the first CPU online would fail since cpufreq_online()
starts with user_policy->min/max as the original limits.

To prevent this scenario, set the limits of the policy passed to
cpufreq_set_policy() to the latest userspace values so that any
inconsistent settings are rejected.

Change-Id: I5ad92ba05162cb5c32c3ba3fdae21d2e505493d3
Signed-off-by: default avatarTaniya Das <tdas@codeaurora.org>
Signed-off-by: default avatarRohit Gupta <rohgup@codeaurora.org>
parent f81ad3ba
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -694,6 +694,9 @@ static ssize_t store_##file_name \
									\
	memcpy(&new_policy, policy, sizeof(*policy));			\
									\
	new_policy.min = new_policy.user_policy.min;			\
	new_policy.max = new_policy.user_policy.max;			\
									\
	ret = sscanf(buf, "%u", &new_policy.object);			\
	if (ret != 1)							\
		return -EINVAL;						\