[PATCH] cpufreq: skip invalid entries when searching the frequency

From: Aaro Koskinen
Date: Mon Oct 10 2016 - 17:38:26 EST


Skip invalid entries when searching the frequency. This fixes cpufreq
at least on loongson2 MIPS board.

Fixes: da0c6dc00c69 ("cpufreq: Handle sorted frequency tables more efficiently")
Signed-off-by: Aaro Koskinen <aaro.koskinen@xxxxxx>
---
include/linux/cpufreq.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 631ba33b..0c1b188 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -645,6 +645,9 @@ static inline int cpufreq_table_find_index_al(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq >= target_freq)
return i;

@@ -665,6 +668,9 @@ static inline int cpufreq_table_find_index_dl(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq == target_freq)
return i;

@@ -706,6 +712,9 @@ static inline int cpufreq_table_find_index_ah(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq == target_freq)
return i;

@@ -735,6 +744,9 @@ static inline int cpufreq_table_find_index_dh(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq <= target_freq)
return i;

@@ -767,6 +779,9 @@ static inline int cpufreq_table_find_index_ac(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq == target_freq)
return i;

@@ -800,6 +815,9 @@ static inline int cpufreq_table_find_index_dc(struct cpufreq_policy *policy,
for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
freq = table[i].frequency;

+ if (freq == CPUFREQ_ENTRY_INVALID)
+ continue;
+
if (freq == target_freq)
return i;

--
2.9.2