diff mbox series

[V2] cpufreq: drivers with target_index() must set freq_table

Message ID 8c788b8029b3a11f012915dad6154e7cc481f997.1680563899.git.viresh.kumar@linaro.org
State Accepted
Commit a038895e25b296ca1ef0254f92673ea64bc1a2ee
Headers show
Series [V2] cpufreq: drivers with target_index() must set freq_table | expand

Commit Message

Viresh Kumar April 3, 2023, 11:39 p.m. UTC
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>
---
V2: Move declaration to cpufreq.h.

 drivers/cpufreq/cpufreq.c    | 5 +++++
 drivers/cpufreq/freq_table.c | 7 ++++++-
 include/linux/cpufreq.h      | 1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki April 7, 2023, 11:22 a.m. UTC | #1
On Tue, Apr 4, 2023 at 1:39 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> 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>
> ---
> V2: Move declaration to cpufreq.h.
>
>  drivers/cpufreq/cpufreq.c    | 5 +++++
>  drivers/cpufreq/freq_table.c | 7 ++++++-
>  include/linux/cpufreq.h      | 1 +
>  3 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 6d8fd3b8dcb5..09131c54703f 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -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);
> diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
> index 90bfc27ed1ba..c4d4643b6ca6 100644
> --- a/drivers/cpufreq/freq_table.c
> +++ b/drivers/cpufreq/freq_table.c
> @@ -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)
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 65623233ab2f..541013487a0e 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -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)
>  {
> --

Applied as 6.4 material, thanks!
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6d8fd3b8dcb5..09131c54703f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -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);
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 90bfc27ed1ba..c4d4643b6ca6 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -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)
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 65623233ab2f..541013487a0e 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -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)
 {