drivers/cpufreq/cpufreq.c | 5 +++++ drivers/cpufreq/freq_table.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
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>
---
drivers/cpufreq/cpufreq.c | 5 +++++
drivers/cpufreq/freq_table.c | 9 ++++++++-
2 files changed, 13 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..c6fc5b0ea91f 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -10,6 +10,8 @@
#include <linux/cpufreq.h>
#include <linux/module.h>
+bool has_target_index(void);
+
/*********************************************************************
* FREQUENCY TABLE HELPERS *
*********************************************************************/
@@ -355,8 +357,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)
--
2.31.1.272.g89b43f80a514
On Mon, Apr 3, 2023 at 6:09 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>
> ---
> drivers/cpufreq/cpufreq.c | 5 +++++
> drivers/cpufreq/freq_table.c | 9 ++++++++-
> 2 files changed, 13 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;
> +}
This needs to go into a header (as a static inline) or the prototype
of it needs to go into a header.
> +
> /* 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..c6fc5b0ea91f 100644
> --- a/drivers/cpufreq/freq_table.c
> +++ b/drivers/cpufreq/freq_table.c
> @@ -10,6 +10,8 @@
> #include <linux/cpufreq.h>
> #include <linux/module.h>
>
> +bool has_target_index(void);
> +
> /*********************************************************************
> * FREQUENCY TABLE HELPERS *
> *********************************************************************/
> @@ -355,8 +357,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)
> --
> 2.31.1.272.g89b43f80a514
>
Hi Viresh,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linus/master v6.3-rc5 next-20230331]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Viresh-Kumar/cpufreq-drivers-with-target_index-must-set-freq_table/20230403-121021
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/53d4ed4e5b18a59a48790434f8146fb207e11c49.1680494945.git.viresh.kumar%40linaro.org
patch subject: [PATCH] cpufreq: drivers with target_index() must set freq_table
config: i386-randconfig-a001-20230403 (https://download.01.org/0day-ci/archive/20230403/202304031904.mo4oksHT-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/3b521388b742e3d7b9bbba198655408c6d152579
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Viresh-Kumar/cpufreq-drivers-with-target_index-must-set-freq_table/20230403-121021
git checkout 3b521388b742e3d7b9bbba198655408c6d152579
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/cpufreq/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304031904.mo4oksHT-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/cpufreq/cpufreq.c:76:6: warning: no previous prototype for function 'has_target_index' [-Wmissing-prototypes]
bool has_target_index(void)
^
drivers/cpufreq/cpufreq.c:76:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
bool has_target_index(void)
^
static
1 warning generated.
vim +/has_target_index +76 drivers/cpufreq/cpufreq.c
75
> 76 bool has_target_index(void)
77 {
78 return !!cpufreq_driver->target_index;
79 }
80
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
Hi Viresh,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linus/master v6.3-rc5 next-20230331]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Viresh-Kumar/cpufreq-drivers-with-target_index-must-set-freq_table/20230403-121021
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/53d4ed4e5b18a59a48790434f8146fb207e11c49.1680494945.git.viresh.kumar%40linaro.org
patch subject: [PATCH] cpufreq: drivers with target_index() must set freq_table
config: riscv-randconfig-r003-20230403 (https://download.01.org/0day-ci/archive/20230403/202304031955.76jRZiQR-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/3b521388b742e3d7b9bbba198655408c6d152579
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Viresh-Kumar/cpufreq-drivers-with-target_index-must-set-freq_table/20230403-121021
git checkout 3b521388b742e3d7b9bbba198655408c6d152579
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/cpufreq/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304031955.76jRZiQR-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/cpufreq/cpufreq.c:76:6: warning: no previous prototype for function 'has_target_index' [-Wmissing-prototypes]
bool has_target_index(void)
^
drivers/cpufreq/cpufreq.c:76:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
bool has_target_index(void)
^
static
1 warning generated.
vim +/has_target_index +76 drivers/cpufreq/cpufreq.c
75
> 76 bool has_target_index(void)
77 {
78 return !!cpufreq_driver->target_index;
79 }
80
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
© 2016 - 2026 Red Hat, Inc.