cpufreq: drivers with target_index() must set freq_table
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 3 Apr 2023 23:39:10 +0000 (05:09 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 7 Apr 2023 11:21:58 +0000 (13:21 +0200)
Since the cpufreq core directly uses freq_table, for cpufreq drivers
that set their target_index() callback, make it mandatory for them to
set the same.

Since this is set per policy and normally from policy->init(), do this
from cpufreq_table_validate_and_sort() which gets called right after
->init().

Reported-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c
drivers/cpufreq/freq_table.c
include/linux/cpufreq.h

index d61f7308f63ccc6f4893ced37bc6a138b32dfa50..b24ed81ba8bd3fe64c1c60bf8d3ab958ea11f656 100644 (file)
@@ -73,6 +73,11 @@ static inline bool has_target(void)
        return cpufreq_driver->target_index || cpufreq_driver->target;
 }
 
+bool has_target_index(void)
+{
+       return !!cpufreq_driver->target_index;
+}
+
 /* internal prototypes */
 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
 static int cpufreq_init_governor(struct cpufreq_policy *policy);
index 67e56cf638efb86a3f26c811c1d330a778a8bd47..ddd4832bcc0d5564e1f8e00e1c7eb240b742454c 100644 (file)
@@ -355,8 +355,13 @@ int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy)
 {
        int ret;
 
-       if (!policy->freq_table)
+       if (!policy->freq_table) {
+               /* Freq table must be passed by drivers with target_index() */
+               if (has_target_index())
+                       return -EINVAL;
+
                return 0;
+       }
 
        ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
        if (ret)
index 65623233ab2f10a2fc23c5fc37ffc008740e1d06..541013487a0e287e5169b10532c58ce7146ee8de 100644 (file)
@@ -237,6 +237,7 @@ bool cpufreq_supports_freq_invariance(void);
 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
 void cpufreq_enable_fast_switch(struct cpufreq_policy *policy);
 void cpufreq_disable_fast_switch(struct cpufreq_policy *policy);
+bool has_target_index(void);
 #else
 static inline unsigned int cpufreq_get(unsigned int cpu)
 {