thermal/of: Allow users to set governor for a thermal zone in DT

Message ID 20221201085423.10360-1-di.shen@unisoc.com
State New
Headers
Series thermal/of: Allow users to set governor for a thermal zone in DT |

Commit Message

Di Shen Dec. 1, 2022, 8:54 a.m. UTC
  The governor of all thermal zones can be initialized in
thermal_zone_device_register_with_trips(), but it is always the
def_governor, this means the governor of all thermal zones are
the same.

Allow users to set governor for a specific thermal zone in DT, in
this way, users can use different policies for thermal management.

Signed-off-by: Di Shen <di.shen@unisoc.com>
---
 drivers/thermal/thermal_of.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

kernel test robot Dec. 1, 2022, 6:42 p.m. UTC | #1
Hi Di,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/thermal]
[also build test WARNING on linus/master v6.1-rc7 next-20221201]
[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/Di-Shen/thermal-of-Allow-users-to-set-governor-for-a-thermal-zone-in-DT/20221201-165820
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link:    https://lore.kernel.org/r/20221201085423.10360-1-di.shen%40unisoc.com
patch subject: [PATCH] thermal/of: Allow users to set governor for a thermal zone in DT
config: ia64-allyesconfig
compiler: ia64-linux-gcc (GCC) 12.1.0
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/6ac4585641eca02d031f54111ca54507d5a3dc56
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Di-Shen/thermal-of-Allow-users-to-set-governor-for-a-thermal-zone-in-DT/20221201-165820
        git checkout 6ac4585641eca02d031f54111ca54507d5a3dc56
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In function 'thermal_of_parameters_init',
       inlined from 'thermal_of_zone_register' at drivers/thermal/thermal_of.c:626:8:
>> drivers/thermal/thermal_of.c:370:17: warning: 'strncpy' specified bound 20 equals destination size [-Wstringop-truncation]
     370 |                 strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +370 drivers/thermal/thermal_of.c

   351	
   352	static struct thermal_zone_params *thermal_of_parameters_init(struct device_node *np)
   353	{
   354		struct thermal_zone_params *tzp;
   355		int coef[2];
   356		int ncoef = ARRAY_SIZE(coef);
   357		int prop, ret;
   358		const char *governor_name;
   359	
   360		tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
   361		if (!tzp)
   362			return ERR_PTR(-ENOMEM);
   363	
   364		tzp->no_hwmon = true;
   365	
   366		if (!of_property_read_u32(np, "sustainable-power", &prop))
   367			tzp->sustainable_power = prop;
   368	
   369		if (!of_property_read_string(np, "policy", &governor_name))
 > 370			strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
   371	
   372		/*
   373		 * For now, the thermal framework supports only one sensor per
   374		 * thermal zone. Thus, we are considering only the first two
   375		 * values as slope and offset.
   376		 */
   377		ret = of_property_read_u32_array(np, "coefficients", coef, ncoef);
   378		if (ret) {
   379			coef[0] = 1;
   380			coef[1] = 0;
   381		}
   382	
   383		tzp->slope = coef[0];
   384		tzp->offset = coef[1];
   385	
   386		return tzp;
   387	}
   388
  

Patch

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index d4b6335ace15..5dd4101dffb6 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -355,6 +355,7 @@  static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
 	int coef[2];
 	int ncoef = ARRAY_SIZE(coef);
 	int prop, ret;
+	const char *governor_name;
 
 	tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
 	if (!tzp)
@@ -365,6 +366,9 @@  static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
 	if (!of_property_read_u32(np, "sustainable-power", &prop))
 		tzp->sustainable_power = prop;
 
+	if (!of_property_read_string(np, "policy", &governor_name))
+		strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
+
 	/*
 	 * For now, the thermal framework supports only one sensor per
 	 * thermal zone. Thus, we are considering only the first two