intel / thermal_daemon

Thermal daemon for IA
GNU General Public License v2.0
526 stars 117 forks source link

src/thd_cpu_default_binding.cpp - uninitialized max_power in check_cpu_load() #433

Open ColinIanKing opened 5 months ago

ColinIanKing commented 5 months ago

When building thermal-daemon for ClearLinux the following warning occurs:

  CXXLD    thermald
src/thd_cpu_default_binding.cpp: In member function ‘check_cpu_load’:
src/thd_cpu_default_binding.cpp:203:24: warning: ‘max_power’ may be used uninitialized [-Wmaybe-uninitialized]
  203 |         if ((max_power - min_power) < def_starting_power_differential) {
      |                        ^
src/thd_cpu_default_binding.cpp:190:22: note: ‘max_power’ was declared here
  190 |         unsigned int max_power;
      |                      ^

the call to thd_engine->rapl_power_meter.rapl_action_get_power() is passing &max_power and &min_power and if cthd_rapl_power_meter::raplc_action_get_power() is called then max_power and min_power are not set if the domain type does not match the given domain type on the call. I suspect this may never occur, but it maybe useful to defensively set max_power and min_power to clear up the compiler static analysis issues.

spandruvada commented 5 months ago

I got some coverity scan report, let me change this as part of that.