Skip to content

Commit a038895

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: drivers with target_index() must set freq_table
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>
1 parent 175c9df commit a038895

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ static inline bool has_target(void)
7373
return cpufreq_driver->target_index || cpufreq_driver->target;
7474
}
7575

76+
bool has_target_index(void)
77+
{
78+
return !!cpufreq_driver->target_index;
79+
}
80+
7681
/* internal prototypes */
7782
static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
7883
static int cpufreq_init_governor(struct cpufreq_policy *policy);

drivers/cpufreq/freq_table.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,13 @@ int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy)
355355
{
356356
int ret;
357357

358-
if (!policy->freq_table)
358+
if (!policy->freq_table) {
359+
/* Freq table must be passed by drivers with target_index() */
360+
if (has_target_index())
361+
return -EINVAL;
362+
359363
return 0;
364+
}
360365

361366
ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
362367
if (ret)

include/linux/cpufreq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ bool cpufreq_supports_freq_invariance(void);
237237
struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
238238
void cpufreq_enable_fast_switch(struct cpufreq_policy *policy);
239239
void cpufreq_disable_fast_switch(struct cpufreq_policy *policy);
240+
bool has_target_index(void);
240241
#else
241242
static inline unsigned int cpufreq_get(unsigned int cpu)
242243
{

0 commit comments

Comments
 (0)