Skip to content

Commit

Permalink
Fix static analysis issues for thermal daemon for IVI
Browse files Browse the repository at this point in the history
Below issues will be solved with this change.

+------------------------------------+
|Unchecked return value from library |
|Argument cannot be negative         |
|Waiting while holding a lock        |
|Resource leak                       |
|Uninitialized scalar variable       |
|COPY_INSTEAD_OF_MOVE                |
+------------------------------------+

Tracked-On: OAM-125661
Signed-off-by: Manvi Bajaj <[email protected]>
  • Loading branch information
mbajaj02 committed Oct 4, 2024
1 parent 8bbfb23 commit 6e5fa67
Show file tree
Hide file tree
Showing 2 changed files with 482 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
From aae7e4146f3bde2efb6b2504575d423ea38c8db5 Mon Sep 17 00:00:00 2001
From: Manvi Bajaj <[email protected]>
Date: Fri, 6 Sep 2024 11:48:51 +0530
Subject: [PATCH] Coverity fixes for Thermal Daemon

Fixes for thermal daemon coverity for COPY_INSTEAD_OF_MOVE

Signed-off-by: Manvi Bajaj <[email protected]>
---
src/thd_cdev.h | 6 +++---
src/thd_cdev_gen_sysfs.h | 2 +-
src/thd_cdev_rapl_dram.cpp | 2 +-
src/thd_cdev_therm_sys_fs.h | 2 +-
src/thd_engine.cpp | 20 ++++++++++----------
src/thd_engine.h | 2 +-
src/thd_rapl_power_meter.cpp | 2 +-
src/thd_sensor.cpp | 2 +-
src/thd_sensor.h | 2 +-
src/thd_sensor_virtual.cpp | 6 +++---
src/thd_sys_fs.h | 2 +-
src/thd_trip_point.cpp | 2 +-
src/thd_trt_art_reader.h | 2 +-
src/thd_zone_dynamic.cpp | 4 ++--
src/thd_zone_generic.cpp | 2 +-
src/thd_zone_therm_sys_fs.cpp | 2 +-
16 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/thd_cdev.h b/src/thd_cdev.h
index bda1999..0206a95 100644
--- a/src/thd_cdev.h
+++ b/src/thd_cdev.h
@@ -221,10 +221,10 @@ public:
return cdev_sysfs.get_base_path();
}
void set_cdev_type(std::string _type_str) {
- type_str = _type_str;
+ type_str = std::move(_type_str);
}
void set_cdev_alias(std::string _alias_str) {
- alias_str = _alias_str;
+ alias_str = std::move(_alias_str);
}
void set_pid_param(double kp, double ki, double kd) {
pid_ctrl.kp = kp;
@@ -238,7 +238,7 @@ public:
}

void thd_cdev_set_write_prefix(std::string prefix) {
- write_prefix = prefix;
+ write_prefix = std::move(prefix);
}

void cdev_dump() {
diff --git a/src/thd_cdev_gen_sysfs.h b/src/thd_cdev_gen_sysfs.h
index f5c76a4..4cb6c82 100644
--- a/src/thd_cdev_gen_sysfs.h
+++ b/src/thd_cdev_gen_sysfs.h
@@ -31,7 +31,7 @@ protected:

public:
cthd_gen_sysfs_cdev(unsigned int _index, std::string control_path) :
- cthd_cdev(_index, control_path) {
+ cthd_cdev(_index, std::move(control_path)) {
}
virtual void set_curr_state(int state, int arg);
virtual void set_curr_state_raw(int state, int arg);
diff --git a/src/thd_cdev_rapl_dram.cpp b/src/thd_cdev_rapl_dram.cpp
index c2196aa..02a7148 100644
--- a/src/thd_cdev_rapl_dram.cpp
+++ b/src/thd_cdev_rapl_dram.cpp
@@ -62,7 +62,7 @@ int cthd_sysfs_cdev_rapl_dram::update() {
if (!found)
return THD_ERROR;

- cdev_sysfs.update_path(path_name);
+ cdev_sysfs.update_path(std::move(path_name));

return cthd_sysfs_cdev_rapl::update();
}
diff --git a/src/thd_cdev_therm_sys_fs.h b/src/thd_cdev_therm_sys_fs.h
index aad52cf..1e08ec9 100644
--- a/src/thd_cdev_therm_sys_fs.h
+++ b/src/thd_cdev_therm_sys_fs.h
@@ -32,7 +32,7 @@ protected:

public:
cthd_sysfs_cdev(unsigned int _index, std::string control_path) :
- cthd_cdev(_index, control_path) {
+ cthd_cdev(_index, std::move(control_path)) {
}
virtual void set_curr_state(int state, int arg);
virtual int get_curr_state();
diff --git a/src/thd_engine.cpp b/src/thd_engine.cpp
index 53930ef..828f6af 100644
--- a/src/thd_engine.cpp
+++ b/src/thd_engine.cpp
@@ -939,7 +939,7 @@ int cthd_engine::user_add_sensor(std::string name, std::string path) {
return THD_SUCCESS;
}
}
- sensor = new cthd_sensor(current_sensor_index, path, name, SENSOR_TYPE_RAW);
+ sensor = new cthd_sensor(current_sensor_index, std::move(path), std::move(name), SENSOR_TYPE_RAW);
if (sensor->sensor_update() != THD_SUCCESS) {
delete sensor;
pthread_mutex_unlock(&thd_engine_mutex);
@@ -979,8 +979,8 @@ int cthd_engine::user_add_virtual_sensor(std::string name,
}
cthd_sensor_virtual *virt_sensor;

- virt_sensor = new cthd_sensor_virtual(current_sensor_index, name,
- dep_sensor, slope, intercept);
+ virt_sensor = new cthd_sensor_virtual(current_sensor_index, std::move(name),
+ std::move(dep_sensor), slope, intercept);
if (virt_sensor->sensor_update() != THD_SUCCESS) {
delete virt_sensor;
pthread_mutex_unlock(&thd_engine_mutex);
@@ -1022,7 +1022,7 @@ int cthd_engine::user_set_psv_temp(std::string name, unsigned int temp) {
int ret;

pthread_mutex_lock(&thd_engine_mutex);
- zone = get_zone(name);
+ zone = get_zone(std::move(name));
if (!zone) {
pthread_mutex_unlock(&thd_engine_mutex);
thd_log_warn("user_set_psv_temp\n");
@@ -1040,7 +1040,7 @@ int cthd_engine::user_set_max_temp(std::string name, unsigned int temp) {
int ret;

pthread_mutex_lock(&thd_engine_mutex);
- zone = get_zone(name);
+ zone = get_zone(std::move(name));
if (!zone) {
pthread_mutex_unlock(&thd_engine_mutex);
thd_log_warn("user_set_max_temp\n");
@@ -1058,7 +1058,7 @@ int cthd_engine::user_add_zone(std::string zone_name, unsigned int trip_temp,
int ret = THD_SUCCESS;

cthd_zone_dynamic *zone = new cthd_zone_dynamic(current_zone_index,
- zone_name, trip_temp, PASSIVE, sensor_name, cdev_name);
+ std::move(zone_name), trip_temp, PASSIVE, std::move(sensor_name), std::move(cdev_name));
if (!zone) {
return THD_ERROR;
}
@@ -1081,7 +1081,7 @@ int cthd_engine::user_set_zone_status(std::string name, int status) {
cthd_zone *zone;

pthread_mutex_lock(&thd_engine_mutex);
- zone = get_zone(name);
+ zone = get_zone(std::move(name));
if (!zone) {
pthread_mutex_unlock(&thd_engine_mutex);
return THD_ERROR;
@@ -1102,7 +1102,7 @@ int cthd_engine::user_get_zone_status(std::string name, int *status) {
cthd_zone *zone;

pthread_mutex_lock(&thd_engine_mutex);
- zone = get_zone(name);
+ zone = get_zone(std::move(name));
if (!zone) {
pthread_mutex_unlock(&thd_engine_mutex);
return THD_ERROR;
@@ -1146,12 +1146,12 @@ int cthd_engine::user_add_cdev(std::string cdev_name, std::string cdev_path,
if (!cdev) {
cthd_gen_sysfs_cdev *cdev_sysfs;

- cdev_sysfs = new cthd_gen_sysfs_cdev(current_cdev_index, cdev_path);
+ cdev_sysfs = new cthd_gen_sysfs_cdev(current_cdev_index, std::move(cdev_path));
if (!cdev_sysfs) {
pthread_mutex_unlock(&thd_engine_mutex);
return THD_ERROR;
}
- cdev_sysfs->set_cdev_type(cdev_name);
+ cdev_sysfs->set_cdev_type(std::move(cdev_name));
if (cdev_sysfs->update() != THD_SUCCESS) {
delete cdev_sysfs;
pthread_mutex_unlock(&thd_engine_mutex);
diff --git a/src/thd_engine.h b/src/thd_engine.h
index c9f103b..85050c3 100644
--- a/src/thd_engine.h
+++ b/src/thd_engine.h
@@ -222,7 +222,7 @@ public:
return preference;
}
void set_config_file(std::string conf_file) {
- config_file = conf_file;
+ config_file = std::move(conf_file);
}
std::string get_config_file() {
return config_file;
diff --git a/src/thd_rapl_power_meter.cpp b/src/thd_rapl_power_meter.cpp
index 204a15f..1eb784b 100644
--- a/src/thd_rapl_power_meter.cpp
+++ b/src/thd_rapl_power_meter.cpp
@@ -107,7 +107,7 @@ void cthd_rapl_power_meter::rapl_read_domains(const char *dir_name) {
domain.type = DRAM;
}
if (measure_mask & domain.type) {
- domain.name = buffer;
+ domain.name = std::move(buffer);
domain.path = std::string(dir_name)
+ std::string(dir_entry->d_name);
domain_list.push_back(domain);
diff --git a/src/thd_sensor.cpp b/src/thd_sensor.cpp
index 8d9604c..520e60b 100644
--- a/src/thd_sensor.cpp
+++ b/src/thd_sensor.cpp
@@ -28,7 +28,7 @@
cthd_sensor::cthd_sensor(int _index, std::string control_path,
std::string _type_str, int _type) :
index(_index), type(_type), sensor_sysfs(control_path.c_str()), sensor_active(
- false), type_str(_type_str), async_capable(false), virtual_sensor(
+ false), type_str(std::move(_type_str)), async_capable(false), virtual_sensor(
false), thresholds(0), scale(1) {

}
diff --git a/src/thd_sensor.h b/src/thd_sensor.h
index df84d05..300271f 100644
--- a/src/thd_sensor.h
+++ b/src/thd_sensor.h
@@ -69,7 +69,7 @@ public:
int set_threshold(int index, int temp);
;
void update_path(std::string str) {
- sensor_sysfs.update_path(str);
+ sensor_sysfs.update_path(std::move(str));
}
void set_async_capable(bool capable) {
async_capable = capable;
diff --git a/src/thd_sensor_virtual.cpp b/src/thd_sensor_virtual.cpp
index 4cdd966..568064a 100644
--- a/src/thd_sensor_virtual.cpp
+++ b/src/thd_sensor_virtual.cpp
@@ -26,8 +26,8 @@

cthd_sensor_virtual::cthd_sensor_virtual(int _index, std::string _type_str,
std::string _link_type_str, double _multiplier, double _offset) :
- cthd_sensor(_index, "none", _type_str), link_sensor(NULL), link_type_str(
- _link_type_str), multiplier(_multiplier), offset(_offset) {
+ cthd_sensor(_index, "none", std::move(_type_str)), link_sensor(NULL), link_type_str(
+ std::move(_link_type_str)), multiplier(_multiplier), offset(_offset) {
virtual_sensor = true;
}

@@ -59,7 +59,7 @@ unsigned int cthd_sensor_virtual::read_temperature() {

int cthd_sensor_virtual::sensor_update_param(std::string new_dep_sensor, double slope, double intercept)
{
- cthd_sensor *sensor = thd_engine->search_sensor(new_dep_sensor);
+ cthd_sensor *sensor = thd_engine->search_sensor(std::move(new_dep_sensor));

if (sensor)
link_sensor = sensor;
diff --git a/src/thd_sys_fs.h b/src/thd_sys_fs.h
index 537329e..c8cac11 100644
--- a/src/thd_sys_fs.h
+++ b/src/thd_sys_fs.h
@@ -73,7 +73,7 @@ public:
mode_t get_mode(const std::string &path);

void update_path(std::string path) {
- base_path = path;
+ base_path = std::move(path);
}
};

diff --git a/src/thd_trip_point.cpp b/src/thd_trip_point.cpp
index 58b09bb..50c9112 100644
--- a/src/thd_trip_point.cpp
+++ b/src/thd_trip_point.cpp
@@ -44,7 +44,7 @@ void cthd_trip_point::set_dependency(std::string cdev, std::string state_str)
{
cthd_cdev *cdev_ptr;

- cdev_ptr = thd_engine->search_cdev(cdev);
+ cdev_ptr = thd_engine->search_cdev(std::move(cdev));
if (cdev_ptr) {
int match;
int state_index = 0;
diff --git a/src/thd_trt_art_reader.h b/src/thd_trt_art_reader.h
index db8b012..d30f586 100644
--- a/src/thd_trt_art_reader.h
+++ b/src/thd_trt_art_reader.h
@@ -45,7 +45,7 @@ struct rel_object_t {

rel_object_t(std::string name) {
target_device = name;
- target_sensor = name;
+ target_sensor = std::move(name);
}
};

diff --git a/src/thd_zone_dynamic.cpp b/src/thd_zone_dynamic.cpp
index 4009b67..b14fc5d 100644
--- a/src/thd_zone_dynamic.cpp
+++ b/src/thd_zone_dynamic.cpp
@@ -10,8 +10,8 @@

cthd_zone_dynamic::cthd_zone_dynamic(int index, std::string _name,
unsigned int _trip_temp, trip_point_type_t _trip_type, std::string _sensor, std::string _cdev) :
- cthd_zone(index, ""), name(_name), trip_temp(_trip_temp), trip_type(_trip_type), sensor_name(
- _sensor), cdev_name(_cdev) {
+ cthd_zone(index, ""), name(std::move(_name)), trip_temp(_trip_temp), trip_type(_trip_type), sensor_name(
+ std::move(_sensor)), cdev_name(std::move(_cdev)) {
type_str = name;
}

diff --git a/src/thd_zone_generic.cpp b/src/thd_zone_generic.cpp
index 3d60bf7..c05752a 100644
--- a/src/thd_zone_generic.cpp
+++ b/src/thd_zone_generic.cpp
@@ -28,7 +28,7 @@
cthd_zone_generic::cthd_zone_generic(int index, int _config_index,
std::string type) :
cthd_zone(index, ""), config_index(_config_index) {
- type_str = type;
+ type_str = std::move(type);

}

diff --git a/src/thd_zone_therm_sys_fs.cpp b/src/thd_zone_therm_sys_fs.cpp
index 0e3c25e..dacc463 100644
--- a/src/thd_zone_therm_sys_fs.cpp
+++ b/src/thd_zone_therm_sys_fs.cpp
@@ -27,7 +27,7 @@
#include <stdlib.h>

cthd_sysfs_zone::cthd_sysfs_zone(int count, std::string path) :
- cthd_zone(count, path), trip_point_cnt(0) {
+ cthd_zone(count, std::move(path)), trip_point_cnt(0) {

std::stringstream tc_type_dev;
tc_type_dev << index << "/type";
--
2.34.1

Loading

0 comments on commit 6e5fa67

Please sign in to comment.