Skip to content

Commit d394abc

Browse files
Shivnandan Kumarrafaeljw
authored andcommitted
cpufreq: Limit resolving a frequency to policy min/max
Resolving a frequency to an efficient one should not transgress policy->max (which can be set for thermal reason) and policy->min. Currently, there is possibility where scaling_cur_freq can exceed scaling_max_freq when scaling_max_freq is an inefficient frequency. Add a check to ensure that resolving a frequency will respect policy->min/max. Cc: All applicable <[email protected]> Fixes: 1f39fa0 ("cpufreq: Introducing CPUFREQ_RELATION_E") Signed-off-by: Shivnandan Kumar <[email protected]> [ rjw: Whitespace adjustment, changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8164f74 commit d394abc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

include/linux/cpufreq.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,18 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
10201020
efficiencies);
10211021
}
10221022

1023+
static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy, int idx)
1024+
{
1025+
unsigned int freq;
1026+
1027+
if (idx < 0)
1028+
return false;
1029+
1030+
freq = policy->freq_table[idx].frequency;
1031+
1032+
return freq == clamp_val(freq, policy->min, policy->max);
1033+
}
1034+
10231035
static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
10241036
unsigned int target_freq,
10251037
unsigned int relation)
@@ -1053,7 +1065,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
10531065
return 0;
10541066
}
10551067

1056-
if (idx < 0 && efficiencies) {
1068+
/* Limit frequency index to honor policy->min/max */
1069+
if (!cpufreq_is_in_limits(policy, idx) && efficiencies) {
10571070
efficiencies = false;
10581071
goto retry;
10591072
}

0 commit comments

Comments
 (0)