From fc1229fc27dd8171591c88ccb4caf68084108065 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 18 Oct 2018 16:40:04 +0900 Subject: [PATCH 01/16] pass: Replace obsolescent ato[if] functions with strto[ld] Replace obsolescent ato[if] functions with recommended strto[ld] according to codingy guide[1]. [1] https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions Change-Id: I23342d7312c1fe77b3734cb23b57948ceac7832b Signed-off-by: Chanwoo Choi --- include/pass/common.h | 2 +- src/core/common.c | 19 ++- src/pass/pass-parser.c | 304 +++++++++++++++++++++++++++++++------------ src/pmqos/pmqos-parser.c | 13 +- src/thermal/thermal-parser.c | 7 +- 5 files changed, 256 insertions(+), 89 deletions(-) diff --git a/include/pass/common.h b/include/pass/common.h index b11571d..4f6a7aa 100644 --- a/include/pass/common.h +++ b/include/pass/common.h @@ -92,5 +92,5 @@ typedef unsigned long long uint64; int sys_get_int(char *fname, int *val); int sys_get_str(char *fname, char *str); - +int sys_strtol(char *str); #endif /* __CORE_COMMON_H__ */ diff --git a/src/core/common.c b/src/core/common.c index 6e2150a..cdc25e7 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,10 @@ int sys_get_int(char *fname, int *val) int ret = 0; if (sys_read_buf(fname, buf) == 0) { - *val = atoi(buf); + ret = sys_strtol(buf); + if (ret < 0) + return ret; + *val = ret; } else { *val = -1; ret = -EIO; @@ -86,3 +90,16 @@ int sys_get_str(char *fname, char *str) return -1; } + +int sys_strtol(char *str) +{ + long value; + + value = strtol(str, (char**)NULL, 10); + if (value > INT_MAX || value < INT_MIN) { + _E("%s is out of range of integer\n", str); + return -EINVAL; + } + + return (int)value; +} diff --git a/src/pass/pass-parser.c b/src/pass/pass-parser.c index b653e76..856270d 100644 --- a/src/pass/pass-parser.c +++ b/src/pass/pass-parser.c @@ -44,8 +44,9 @@ #include "pass.h" -#define MAX_NUM 255 -#define MIN_TIMEOUT_SEC 0.2 +#define MAX_NUM 255 +#define MIN_TIMEOUT_SEC 0.2 /* 200 millisecond */ +#define MAX_TIMEOUT_SEC 3600.0 /* 1 hour */ static int compare_compatible_name(char *compatible, char *path_compatible) { @@ -100,6 +101,8 @@ static enum pass_state is_supported(char *value) static int parse_scenario(struct parse_result *result, struct pass_scenario *scenario) { + int ret; + if (!result || !scenario) return 0; @@ -116,15 +119,27 @@ static int parse_scenario(struct parse_result *result, /* Parse properties for only PASS_MODULE_PMQOS */ } else if (MATCH(result->name, "min_level")) { - scenario->pmqos.min_level = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + scenario->pmqos.min_level = ret; } else if (MATCH(result->name, "max_level")) { - scenario->pmqos.max_level = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + scenario->pmqos.max_level = ret; /* Parse properties for only PASS_MODULE_THERMAL */ } else if (MATCH(result->name, "temperature")) { - scenario->thermal.temperature = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + scenario->thermal.temperature = ret; } else if (MATCH(result->name, "timer_interval_ms")) { - scenario->thermal.timer_interval = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + scenario->thermal.timer_interval = ret; } return 0; @@ -139,6 +154,8 @@ static int parse_scenario(struct parse_result *result, static int parse_level(struct parse_result *result, struct pass_level *level) { + int ret; + if (!result || !level) return 0; @@ -151,67 +168,129 @@ static int parse_level(struct parse_result *result, * - PASS_RESOURCE_BUS_ID * - PASS_RESOURCE_GPU_ID */ - if (MATCH(result->name, "limit_max_freq")) - level->limit_max_freq = atoi(result->value); - else if (MATCH(result->name, "limit_min_freq")) - level->limit_min_freq = atoi(result->value); - else if (MATCH(result->name, "limit_min_cpu")) - level->limit_min_cpu = atoi(result->value); + if (MATCH(result->name, "limit_max_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->limit_max_freq = ret; + } else if (MATCH(result->name, "limit_min_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->limit_min_freq = ret; + } else if (MATCH(result->name, "limit_min_cpu")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->limit_min_cpu = ret; /* * Properties for the following h/w resources: * - PASS_RESOURCE_CPU_ID */ - else if (MATCH(result->name, "num_down_cond")) - level->num_down_cond = atoi(result->value); - else if (MATCH(result->name, "num_down_cond_freq")) - level->down_cond[0].freq = atoi(result->value); - else if (MATCH(result->name, "num_down_cond_nr_running")) - level->down_cond[0].nr_running = atoi(result->value); - else if (MATCH(result->name, "num_down_cond_busy_cpu")) - level->down_cond[0].busy_cpu = atoi(result->value); - - else if (MATCH(result->name, "num_up_cond")) - level->num_up_cond = atoi(result->value); - else if (MATCH(result->name, "num_up_cond_freq")) - level->up_cond[0].freq = atoi(result->value); - else if (MATCH(result->name, "num_up_cond_nr_running")) - level->up_cond[0].nr_running = atoi(result->value); - else if (MATCH(result->name, "num_up_cond_busy_cpu")) - level->up_cond[0].busy_cpu = atoi(result->value); - - else if (MATCH(result->name, "num_left_cond")) - level->num_left_cond = atoi(result->value); - else if (MATCH(result->name, "num_left_cond_freq")) - level->left_cond[0].freq = atoi(result->value); - else if (MATCH(result->name, "num_left_cond_nr_running")) - level->left_cond[0].nr_running = atoi(result->value); - else if (MATCH(result->name, "num_left_cond_busy_cpu")) - level->left_cond[0].busy_cpu = atoi(result->value); - - else if (MATCH(result->name, "num_right_cond")) - level->num_right_cond = atoi(result->value); - else if (MATCH(result->name, "num_right_cond_freq")) - level->right_cond[0].freq = atoi(result->value); - else if (MATCH(result->name, "num_right_cond_nr_running")) - level->right_cond[0].nr_running = atoi(result->value); - else if (MATCH(result->name, "num_right_cond_busy_cpu")) - level->right_cond[0].busy_cpu = atoi(result->value); - else if (MATCH(result->name, "gov_timeout")) { - double gov_timeout = atof(result->value); - - if (gov_timeout < MIN_TIMEOUT_SEC) + } else if (MATCH(result->name, "num_down_cond")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->num_down_cond = ret; + } else if (MATCH(result->name, "num_down_cond_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->down_cond[0].freq = ret; + } else if (MATCH(result->name, "num_down_cond_nr_running")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->down_cond[0].nr_running = ret; + } else if (MATCH(result->name, "num_down_cond_busy_cpu")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->down_cond[0].busy_cpu = ret; + + } else if (MATCH(result->name, "num_up_cond")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->num_up_cond = ret; + } else if (MATCH(result->name, "num_up_cond_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->up_cond[0].freq = ret; + } else if (MATCH(result->name, "num_up_cond_nr_running")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->up_cond[0].nr_running = ret; + } else if (MATCH(result->name, "num_up_cond_busy_cpu")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->up_cond[0].busy_cpu = ret; + + } else if (MATCH(result->name, "num_left_cond")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->num_left_cond = ret; + } else if (MATCH(result->name, "num_left_cond_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->left_cond[0].freq = ret; + } else if (MATCH(result->name, "num_left_cond_nr_running")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->left_cond[0].nr_running = ret; + } else if (MATCH(result->name, "num_left_cond_busy_cpu")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->left_cond[0].busy_cpu = ret; + + } else if (MATCH(result->name, "num_right_cond")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->num_right_cond = ret; + } else if (MATCH(result->name, "num_right_cond_freq")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->right_cond[0].freq = ret; + } else if (MATCH(result->name, "num_right_cond_nr_running")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->right_cond[0].nr_running = ret; + } else if (MATCH(result->name, "num_right_cond_busy_cpu")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->right_cond[0].busy_cpu = ret; + + } else if (MATCH(result->name, "gov_timeout")) { + double gov_timeout = strtod(result->value, (char **)NULL); + + if (gov_timeout < MIN_TIMEOUT_SEC + || gov_timeout > MAX_TIMEOUT_SEC) gov_timeout = MIN_TIMEOUT_SEC; level->gov_timeout = gov_timeout; - } /* * Properties for the following h/w resources: * - PASS_RESOURCE_MEMORY_ID */ - else if (MATCH(result->name, "fault_around_bytes")) - level->fault_around_bytes = atoi(result->value); + } else if (MATCH(result->name, "fault_around_bytes")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + level->fault_around_bytes = ret; + } return 0; } @@ -241,8 +320,13 @@ static int parse_pmqos(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "pass_num_scenarios")) { unsigned int num_scenarios; + int ret; + + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + num_scenarios = ret; - num_scenarios = atoi(result->value); if (num_scenarios > MAX_NUM) { _E("cannot parse %s\n", result->name); return -EINVAL; @@ -273,6 +357,7 @@ static int parse_thermal(struct parse_result *result, void *user_data) { struct pass_resource *res = user_data; struct pass_thermal *thermal = &res->thermal; + int ret; if (!result) return 0; @@ -288,7 +373,11 @@ static int parse_thermal(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "thermal_number_of_scenario")) { unsigned int num_scenarios; - num_scenarios = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + num_scenarios = ret; + if (num_scenarios > MAX_NUM) { _E("cannot parse %s\n", result->name); return -EINVAL; @@ -304,7 +393,10 @@ static int parse_thermal(struct parse_result *result, void *user_data) thermal->num_scenarios = num_scenarios; } } else if (MATCH(result->name, "thermal_timer_interval_ms")) { - thermal->timer_interval = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + thermal->timer_interval = ret; } return 0; @@ -319,6 +411,7 @@ static int parse_thermal(struct parse_result *result, void *user_data) static int parse_core(struct parse_result *result, void *user_data) { struct pass_resource *res = user_data; + int ret; if (!result) return 0; @@ -326,35 +419,66 @@ static int parse_core(struct parse_result *result, void *user_data) if (!result->section || !result->name || !result->value) return 0; - if (MATCH(result->name, "pass_support")) - res->config_data.state = atoi(result->value); - else if (MATCH(result->name, "pass_gov_type")) - res->config_data.gov_type = atoi(result->value); - else if (MATCH(result->name, "pass_num_levels")) { - unsigned int num_levels = atoi(result->value); + if (MATCH(result->name, "pass_support")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->config_data.state = ret; + } else if (MATCH(result->name, "pass_gov_type")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->config_data.gov_type = ret; + } else if (MATCH(result->name, "pass_num_levels")) { + unsigned int num_levels; + + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + num_levels = ret; if (num_levels > MAX_NUM) { _E("cannot parse %s\n", result->name); return -EINVAL; } res->config_data.num_levels = num_levels; - } else if (MATCH(result->name, "pass_min_level")) - res->rescon.min_level = atoi(result->value); - else if (MATCH(result->name, "pass_max_level")) - res->rescon.max_level = atoi(result->value); - else if (MATCH(result->name, "pass_init_level")) - res->rescon.init_level = atoi(result->value); - - else if (MATCH(result->name, "pass_cpu_threshold")) - res->cpuhp.pass_cpu_threshold = atoi(result->value); - else if (MATCH(result->name, "pass_up_threshold")) - res->cpuhp.up_threshold = atoi(result->value); - else if (MATCH(result->name, "pass_down_threshold")) - res->cpuhp.down_threshold = atoi(result->value); - else if (MATCH(result->name, "pass_governor_timeout")) { - res->config_data.gov_timeout = atof(result->value); - - if (MIN_TIMEOUT_SEC > res->config_data.gov_timeout) + } else if (MATCH(result->name, "pass_min_level")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->rescon.min_level = ret; + } else if (MATCH(result->name, "pass_max_level")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->rescon.max_level = ret; + } else if (MATCH(result->name, "pass_init_level")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->rescon.init_level = ret; + + } else if (MATCH(result->name, "pass_cpu_threshold")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->cpuhp.pass_cpu_threshold = ret; + } else if (MATCH(result->name, "pass_up_threshold")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->cpuhp.up_threshold = ret; + } else if (MATCH(result->name, "pass_down_threshold")) { + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + res->cpuhp.down_threshold = ret; + } else if (MATCH(result->name, "pass_governor_timeout")) { + res->config_data.gov_timeout + = strtod(result->value, (char **)NULL); + + if (res->config_data.gov_timeout < MIN_TIMEOUT_SEC + || res->config_data.gov_timeout > MAX_TIMEOUT_SEC) res->config_data.gov_timeout = MIN_TIMEOUT_SEC; } @@ -486,6 +610,7 @@ static int parse_resource_data(struct parse_result *result, struct pass *pass = user_data; struct pass_resource_config_data *config_data = &(pass->res[id].config_data); + int ret; if (!result) return 0; @@ -522,7 +647,10 @@ static int parse_resource_data(struct parse_result *result, switch (res_type) { case PASS_RESOURCE_CPU_ID: - config_data->cpu = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + config_data->cpu = ret; break; default: return -EINVAL; @@ -532,7 +660,10 @@ static int parse_resource_data(struct parse_result *result, switch (res_type) { case PASS_RESOURCE_CPU_ID: - config_data->num_cpus = atoi(result->value); + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + config_data->num_cpus = ret; break; default: return -EINVAL; @@ -591,8 +722,13 @@ static int parse_resource(struct parse_result *result, void *user_data) is_compatible = true; } } else if (MATCH(result->name, "pass_num_resources")) { - unsigned int num_resources = atoi(result->value); - int i; + unsigned int num_resources; + int i, ret; + + ret = sys_strtol(result->value); + if (ret < 0) + return ret; + num_resources = ret; if ((num_resources > MAX_NUM) || (num_resources < 1)) { diff --git a/src/pmqos/pmqos-parser.c b/src/pmqos/pmqos-parser.c index 168c78e..ccb382d 100644 --- a/src/pmqos/pmqos-parser.c +++ b/src/pmqos/pmqos-parser.c @@ -35,6 +35,7 @@ #include #include +#include #include #include "pmqos.h" @@ -70,7 +71,11 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un if (MATCH(result->name, "scenario_support")) scenarios->support = is_supported(result->value); else if (MATCH(result->name, "scenario_num")) { - int num = atoi(result->value); + int num; + + num = sys_strtol(result->value); + if (num < 0) + return num; if (num > MAX_NUM_OF_SCENARIOS) return -EINVAL; @@ -86,7 +91,11 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un scenarios->num = num; } } else if (MATCH(result->name, "scenario_max_timeout_ms")) { - int max_timeout_ms = atoi(result->value); + int max_timeout_ms; + + max_timeout_ms = sys_strtol(result->value); + if (max_timeout_ms < 0) + return max_timeout_ms; if (max_timeout_ms < 0) { _E("failed to get maximum timeout of scenario"); diff --git a/src/thermal/thermal-parser.c b/src/thermal/thermal-parser.c index 6b3dd8d..df65bb1 100644 --- a/src/thermal/thermal-parser.c +++ b/src/thermal/thermal-parser.c @@ -36,6 +36,7 @@ #include #include +#include #include #include "thermal.h" @@ -72,7 +73,11 @@ static int thermal_parse_scenario(struct parse_result *result, void *user_data, if (MATCH(result->name, "thermal_support")) scenarios->support = is_supported(result->value); else if (MATCH(result->name, "thermal_number_of_scenario")) { - int num = atoi(result->value); + int num; + + num = sys_strtol(result->value); + if (num < 0) + return num; if (num > MAX_NUM_OF_SCENARIOS) return -EINVAL; -- 2.7.4 From 375ae72a8ffd3048e01d3d1959ac91bb722bd35a Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 19 Oct 2018 11:43:04 +0900 Subject: [PATCH 02/16] pass: Fix coverity and svace reported issue Change-Id: Ic36b58d4cf04023d733360f30cb186bd3a57ce2e Signed-off-by: Chanwoo Choi --- src/pass/pass-parser.c | 20 ++++++++++++-------- src/pmqos/pmqos-parser.c | 5 +---- src/thermal/thermal-parser.c | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/pass/pass-parser.c b/src/pass/pass-parser.c index 856270d..2828743 100644 --- a/src/pass/pass-parser.c +++ b/src/pass/pass-parser.c @@ -420,15 +420,19 @@ static int parse_core(struct parse_result *result, void *user_data) return 0; if (MATCH(result->name, "pass_support")) { - ret = sys_strtol(result->value); - if (ret < 0) - return ret; - res->config_data.state = ret; + int state; + + state = sys_strtol(result->value); + if (state < 0) + return state; + res->config_data.state = state; } else if (MATCH(result->name, "pass_gov_type")) { - ret = sys_strtol(result->value); - if (ret < 0) - return ret; - res->config_data.gov_type = ret; + int gov_type; + + gov_type = sys_strtol(result->value); + if (gov_type < 0) + return gov_type; + res->config_data.gov_type = gov_type; } else if (MATCH(result->name, "pass_num_levels")) { unsigned int num_levels; diff --git a/src/pmqos/pmqos-parser.c b/src/pmqos/pmqos-parser.c index ccb382d..7797237 100644 --- a/src/pmqos/pmqos-parser.c +++ b/src/pmqos/pmqos-parser.c @@ -94,9 +94,6 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un int max_timeout_ms; max_timeout_ms = sys_strtol(result->value); - if (max_timeout_ms < 0) - return max_timeout_ms; - if (max_timeout_ms < 0) { _E("failed to get maximum timeout of scenario"); return -ERANGE; @@ -114,7 +111,7 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un return 0; /* No item to parse */ - if (index > scenarios->num) + if (index >= scenarios->num) return 0; /* Parse 'Scenario' section */ diff --git a/src/thermal/thermal-parser.c b/src/thermal/thermal-parser.c index df65bb1..7dfdaf1 100644 --- a/src/thermal/thermal-parser.c +++ b/src/thermal/thermal-parser.c @@ -98,7 +98,7 @@ static int thermal_parse_scenario(struct parse_result *result, void *user_data, if (!scenarios->support || !scenarios->num) return 0; - if (index > scenarios->num) + if (index >= scenarios->num) return 0; /* Parse 'Scenario' section */ -- 2.7.4 From 261812a0492a8a9ce71c7a3ed620a998b3fbfab8 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 19 Oct 2018 17:01:32 +0900 Subject: [PATCH 03/16] core: Remove unneeded codes Change-Id: I6bc9acdc601e9d9d0b1ac9885c7cf952cde2467f Signed-off-by: Chanwoo Choi --- include/pass/common.h | 1 - include/pass/devices.h | 56 -------------------------------------------------- src/core/common.c | 22 +------------------- src/core/devices.c | 20 ------------------ 4 files changed, 1 insertion(+), 98 deletions(-) diff --git a/include/pass/common.h b/include/pass/common.h index 4f6a7aa..3bef731 100644 --- a/include/pass/common.h +++ b/include/pass/common.h @@ -90,7 +90,6 @@ typedef unsigned long long uint64; #define USEC_TO_MSEC(x) ((double)x/1000) #endif -int sys_get_int(char *fname, int *val); int sys_get_str(char *fname, char *str); int sys_strtol(char *str); #endif /* __CORE_COMMON_H__ */ diff --git a/include/pass/devices.h b/include/pass/devices.h index 38bad23..dd0bd27 100644 --- a/include/pass/devices.h +++ b/include/pass/devices.h @@ -54,48 +54,6 @@ enum device_ops_status { void devices_init(void *data); void devices_exit(void *data); -static inline int device_start(const struct device_ops *dev) -{ - if (dev && dev->start) - return dev->start(NORMAL_MODE); - - return -EINVAL; -} - -static inline int device_stop(const struct device_ops *dev) -{ - if (dev && dev->stop) - return dev->stop(NORMAL_MODE); - - return -EINVAL; -} - -static inline int device_exit(const struct device_ops *dev, void *data) -{ - if (dev && dev->exit) { - dev->exit(data); - return 0; - } - - return -EINVAL; -} - -static inline int device_execute(const struct device_ops *dev, void *data) -{ - if (dev && dev->execute) - return dev->execute(data); - - return -EINVAL; -} - -static inline int device_get_status(const struct device_ops *dev) -{ - if (dev && dev->status) - return dev->status(); - - return -EINVAL; -} - #define DEVICE_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ module_init(void) \ { \ @@ -108,18 +66,4 @@ static void __DESTRUCTOR__ module_exit(void) \ void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); - -const struct device_ops *find_device(const char *name); -int check_default(const struct device_ops *dev); - -#define NOT_SUPPORT_OPS(dev) ((check_default(dev)) ? 1 : 0) - -#define FIND_DEVICE_INT(dev, name) do { \ - if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \ -} while (0) - -#define FIND_DEVICE_VOID(dev, name) do { \ - if (!dev) dev = find_device(name); if (check_default(dev)) return; \ -} while (0) - #endif diff --git a/src/core/common.c b/src/core/common.c index cdc25e7..bf1a81b 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -61,24 +61,6 @@ static int sys_read_buf(char *file, char *buf) return ret; } -int sys_get_int(char *fname, int *val) -{ - char buf[BUFF_MAX]; - int ret = 0; - - if (sys_read_buf(fname, buf) == 0) { - ret = sys_strtol(buf); - if (ret < 0) - return ret; - *val = ret; - } else { - *val = -1; - ret = -EIO; - } - - return ret; -} - int sys_get_str(char *fname, char *str) { char buf[BUFF_MAX] = {0}; @@ -96,10 +78,8 @@ int sys_strtol(char *str) long value; value = strtol(str, (char**)NULL, 10); - if (value > INT_MAX || value < INT_MIN) { - _E("%s is out of range of integer\n", str); + if (value > INT_MAX || value < INT_MIN) return -EINVAL; - } return (int)value; } diff --git a/src/core/devices.c b/src/core/devices.c index 42e193c..0e7b969 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -42,26 +42,6 @@ void remove_device(const struct device_ops *dev) dev_head = g_list_remove(dev_head, (gconstpointer)dev); } -const struct device_ops *find_device(const char *name) -{ - GList *elem; - const struct device_ops *dev; - - for (elem = dev_head; elem != NULL; elem = elem->next) { - dev = elem->data; - if (!strcmp(dev->name, name)) - return dev; - } - - dev = &default_ops; - return dev; -} - -int check_default(const struct device_ops *dev) -{ - return (dev == &default_ops); -} - void devices_init(void *data) { GList *elem, *elem_n; -- 2.7.4 From 3e9b50afbc8507a0a03d9ad6b749e4949b0f2295 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 19 Oct 2018 17:02:51 +0900 Subject: [PATCH 04/16] scripts: pmqos: Add default maximum duration value to keep scenario PMQoS keeps the scenario during the required duration. But if the required duration is over than defined maximum duration, PMQoS changes the required duration value by using the defined maximum duration value. So, specify the default mamximum duration value of PMQoS. Change-Id: Ieab7d6acfd4bd1cdfff7a2d730776441588b805d Signed-off-by: Chanwoo Choi --- scripts/pass-pmqos.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pass-pmqos.conf b/scripts/pass-pmqos.conf index 6305903..a47733c 100644 --- a/scripts/pass-pmqos.conf +++ b/scripts/pass-pmqos.conf @@ -4,6 +4,7 @@ # set scenario_max_timeout_ms (unit:millisecond, default timeout is 3000ms) scenario_support=yes scenario_num=2 +scenario_max_timeout_ms=3000 # describe the scenario section as follows #[Scenario0] -- 2.7.4 From c808bc71a8f61570097e621456c8c86bfaf08534 Mon Sep 17 00:00:00 2001 From: Suchang Woo Date: Tue, 23 Oct 2018 17:14:07 +0900 Subject: [PATCH 05/16] pass: Fix typo Change-Id: I5cce6c6c2a697e78a5871ad8482b1e1c66209293 Signed-off-by: Suchang Woo --- include/pass/hal/hal.h | 4 ++-- src/pass/pass-resmon-internal.h | 6 +++--- src/pass/pass-resmon.c | 14 +++++++------- src/pass/pass-resmon.h | 14 +++++++------- src/pass/pass-thermal.c | 2 +- src/pass/pass.c | 2 +- src/pass/pass.h | 6 +++--- src/pmqos/pmqos-parser.c | 2 +- src/pmqos/pmqos.c | 4 ++-- unittest/pass_gtest.cpp | 2 +- unittest/pass_haltests.cpp | 6 +++--- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/pass/hal/hal.h b/include/pass/hal/hal.h index b9e2699..3e41493 100644 --- a/include/pass/hal/hal.h +++ b/include/pass/hal/hal.h @@ -140,8 +140,8 @@ struct pass_resource_hotplug_ops { }; struct pass_resource_tmu_ops { - /* Get the current temperature of resoruce. */ - int (*get_temp)(char *res_thremal_name); + /* Get the current temperature of resource. */ + int (*get_temp)(char *res_thermal_name); /* Get the policy of thermal management unit. */ int (*get_policy)(char *res_thermal_name, char *policy); diff --git a/src/pass/pass-resmon-internal.h b/src/pass/pass-resmon-internal.h index d49be99..0b3563f 100644 --- a/src/pass/pass-resmon-internal.h +++ b/src/pass/pass-resmon-internal.h @@ -59,12 +59,12 @@ struct resmon_ops { int (*uevent_handler)(struct resmon *monitor, void *result, struct udev_device *dev); /** - * Intance of uevent subsystem. It will be used for only uevent-based + * Instance of uevent subsystem. It will be used for only uevent-based * resource monitor. */ const char *uevent_subsystem; /** - * Intance of uevent device type. It will be used for only uevent-based + * Instance of uevent device type. It will be used for only uevent-based * resource monitor. */ const char *uevent_devtype; @@ -123,7 +123,7 @@ struct resmon { * File descriptor for udev device. It will be only used for * uevent-based resource monitor. */ - guint udev_moniotr_fd; + guint udev_monitor_fd; }; #endif /* __PASS_RESMON_INTERNAL__ */ diff --git a/src/pass/pass-resmon.c b/src/pass/pass-resmon.c index dc32337..7b644ce 100644 --- a/src/pass/pass-resmon.c +++ b/src/pass/pass-resmon.c @@ -338,7 +338,7 @@ int pass_resmon_register_timer(struct pass_resource *res, monitor->user_func = user_func; monitor->user_data = user_data; - /* Get instance of struct resmon_ops accoring to resmon_src_type */ + /* Get instance of struct resmon_ops according to resmon_src_type */ monitor->ops = resmon_get_ops(src_type); if (!monitor->ops) { ret = -EINVAL; @@ -512,7 +512,7 @@ static int resmon_uevent_add(struct resmon *monitor) } /* - * At least, either uevent_subsystem or uevet_devtype should be not NULL + * At least, either uevent_subsystem or uevent_devtype should be not NULL */ if (!monitor->ops->uevent_subsystem && !monitor->ops->uevent_devtype) { _E("failed to add filter due to subsystem/devtype are NULL " \ @@ -579,7 +579,7 @@ static int resmon_uevent_add(struct resmon *monitor) /* Bind udev-monitor to enable the udev monitoring */ ret = udev_monitor_enable_receiving(udev_monitor); if (ret < 0) { - _E("failed to bind udev monitor for receving the event " \ + _E("failed to bind udev monitor for receiving the event " \ "(res_name:%s, src_type: 0x%x)\n", res->config_data.res_name, monitor->src_type); ret = -EAGAIN; @@ -592,7 +592,7 @@ static int resmon_uevent_add(struct resmon *monitor) resmon->uevent_state |= monitor->src_type; monitor->udev_monitor = udev_monitor;; - monitor->udev_moniotr_fd = gfd; + monitor->udev_monitor_fd = gfd; return 0; @@ -630,9 +630,9 @@ static int resmon_uevent_delete(struct resmon *monitor) } udev_monitor_unref(monitor->udev_monitor); - g_source_remove(monitor->udev_moniotr_fd); + g_source_remove(monitor->udev_monitor_fd); monitor->udev_monitor = NULL; - monitor->udev_moniotr_fd = -1; + monitor->udev_monitor_fd = -1; /* Delete the uevent-based resmon from uevent_list */ resmon->uevent_state &= ~(monitor->src_type); @@ -693,7 +693,7 @@ int pass_resmon_register_uevent(struct pass_resource *res, monitor->user_func = user_func; monitor->user_data = user_data; - /* Get instance of struct resmon_ops accoring to resmon_src_type */ + /* Get instance of struct resmon_ops according to resmon_src_type */ monitor->ops = resmon_get_ops(src_type); if (!monitor->ops) { _E("failed to get resmon_ops (res_name: %s, type: 0x%x)\n", diff --git a/src/pass/pass-resmon.h b/src/pass/pass-resmon.h index 05f0b7f..a3b6d81 100644 --- a/src/pass/pass-resmon.h +++ b/src/pass/pass-resmon.h @@ -98,14 +98,14 @@ struct resmon_result_src_cpuhp { */ unsigned int *load; - unsigned int *nr_running; /** Unused paramerter will be removed */ - unsigned int *runnable_load; /** Unused paramerter will be removed */ + unsigned int *nr_running; /** Unused parameter will be removed */ + unsigned int *runnable_load; /** Unused parameter will be removed */ - unsigned int num_busy_cpu; /** Unused paramerter will be removed */ - unsigned int avg_load; /** Unused paramerter will be removed */ - unsigned int avg_runnable_load; /** Unused paramerter will be removed */ - unsigned int avg_thread_load; /** Unused paramerter will be removed */ - /** Unused paramerter will be removed */ + unsigned int num_busy_cpu; /** Unused parameter will be removed */ + unsigned int avg_load; /** Unused parameter will be removed */ + unsigned int avg_runnable_load; /** Unused parameter will be removed */ + unsigned int avg_thread_load; /** Unused parameter will be removed */ + /** Unused parameter will be removed */ unsigned int avg_thread_runnable_load; }; diff --git a/src/pass/pass-thermal.c b/src/pass/pass-thermal.c index 8224dea..f47b4ed 100644 --- a/src/pass/pass-thermal.c +++ b/src/pass/pass-thermal.c @@ -83,7 +83,7 @@ static int thermal_monitor_func(void *result, void *user_data) /* * If temperature is lower than defined temperature in configuration - * or if there are no scearnio with 'support=yes', + * or if there are no scenario with 'support=yes', * just return without notification. */ if (scenario_idx < 0) diff --git a/src/pass/pass.c b/src/pass/pass.c index 99bebb8..304df55 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -210,7 +210,7 @@ static int pass_init_resource(struct pass_resource *res) return -1; } - /* Check whether PASS is initialzied state or not */ + /* Check whether PASS is initialized state or not */ if (res->state) { _I("PASS is already active state"); return -1; diff --git a/src/pass/pass.h b/src/pass/pass.h index 5c1bfe7..0e4868e 100644 --- a/src/pass/pass.h +++ b/src/pass/pass.h @@ -225,7 +225,7 @@ struct pass_scenario { struct { /** Locked state of scenario (either locked or unlocked) */ enum pass_state locked; - /** Requiired locking time of scenario */ + /** Required locking time of scenario */ int64_t locked_time; /** Required minimum pass_level */ unsigned int min_level; @@ -308,7 +308,7 @@ struct pass_pmqos { unsigned int curr_level; /** Available minimum level according to locked scenarios */ unsigned int min_level; - /** Availabl maximum level according to locked scenarios */ + /** Available maximum level according to locked scenarios */ unsigned int max_level; }; @@ -551,7 +551,7 @@ struct pass_resource { ******************************************************/ /** - * @brief Represent PASS(Power Aware System Serice). + * @brief Represent PASS(Power Aware System Service). */ struct pass { /** State of PASS daemon */ diff --git a/src/pmqos/pmqos-parser.c b/src/pmqos/pmqos-parser.c index 7797237..5b32bae 100644 --- a/src/pmqos/pmqos-parser.c +++ b/src/pmqos/pmqos-parser.c @@ -84,7 +84,7 @@ static int pmqos_parse_scenario(struct parse_result *result, void *user_data, un scenarios->list = calloc(num, sizeof(struct scenario)); if (!scenarios->list) { - _E("failed to allocat memory for scenario"); + _E("failed to allocate memory for scenario"); return -errno; } diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 13aae69..7ffd98b 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -185,7 +185,7 @@ static gboolean dbus_cb_pmqos_legacy_scenario(SystemPassPmqos *obj, } if (ret < 0) { - _E("cannot set the PMQoS sceanrio: " + _E("cannot set the PMQoS scenario: " "%s is not supported\n", name_from); ret_out = FALSE; goto out_dbus; @@ -510,7 +510,7 @@ static int pmqos_init_done(void *data, void *user_data) _I("Support \'%s\' scenario", g_pmqos->list[i].name); /* - * Set maximum timeout for the sceanrio by using the parsed data from + * Set maximum timeout for the scenario by using the parsed data from * pass-pmqos.conf. But, if there is no setting from pass-pmqos.conf * pmqos uses the default timeout value (3000 millisecond). */ diff --git a/unittest/pass_gtest.cpp b/unittest/pass_gtest.cpp index 54c83f1..dd80a17 100644 --- a/unittest/pass_gtest.cpp +++ b/unittest/pass_gtest.cpp @@ -232,7 +232,7 @@ TEST_F(PowerMgntTest, RestartsPowerMgntService) ASSERT_EQ(ret, 0) << "PassServiceStart Failed"; ret = system("/bin/systemctl stop pass.service"); - ASSERT_EQ(ret, 0) << "PassServieStop Failed"; + ASSERT_EQ(ret, 0) << "PassServiceStop Failed"; ret = system("/bin/systemctl start pass.service"); ASSERT_EQ(ret, 0) << "PassServiceStart Failed"; diff --git a/unittest/pass_haltests.cpp b/unittest/pass_haltests.cpp index 3efc070..3ab4827 100644 --- a/unittest/pass_haltests.cpp +++ b/unittest/pass_haltests.cpp @@ -40,7 +40,7 @@ static int haltest_is_failed(struct pass_resource *res, int ret) /* * If -EPERM, function is not supported according to h/w resource type. * And if -ENODEV, function is not implemented on hal package. - * It means that this funcion is not necessary on two error case + * It means that this function is not necessary on two error case * when calling the HAL functions. */ if (ret < 0) { @@ -61,7 +61,7 @@ TEST_F(PowerMgntHalTest, GetResourceConfig_HandlesValidInput) /* Stop PASS daemon before HAL testing */ ret = system("/bin/systemctl stop pass.service"); - ASSERT_EQ(ret, 0) << "PassServieStop Faield"; + ASSERT_EQ(ret, 0) << "PassServiceStop Failed"; ret = pass_get_resource_config(&g_pass, path); ASSERT_EQ(ret, 0) << "GetResourceConfig Failed"; @@ -466,7 +466,7 @@ TEST_F(PowerMgntHalTest, PutResourceConfig_HandlesValidInput) /* Restart PASS daemon before HAL testing */ ret = system("/bin/systemctl start pass.service"); - ASSERT_EQ(ret, 0) << "PassServiceStart Faield"; + ASSERT_EQ(ret, 0) << "PassServiceStart Failed"; } int main(int argc, char *argv[]) -- 2.7.4 From a3bcb858b2f2de6abd4afbfb72879d09e2285a44 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 11 Dec 2018 10:42:57 +0900 Subject: [PATCH 06/16] pass: Fix wrong format string Change-Id: I5f58009a26e4a29dbf0031c67981961f5fa1fd91 Signed-off-by: Dongwoo Lee --- src/pass/pass-cpuhp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pass/pass-cpuhp.c b/src/pass/pass-cpuhp.c index dfc4536..d659416 100644 --- a/src/pass/pass-cpuhp.c +++ b/src/pass/pass-cpuhp.c @@ -289,7 +289,7 @@ static int cpuhp_governor_init(struct pass_resource *res) struct pass_cpuhp *cpuhp = &res->cpuhp; if (res->config_data.gov_timeout < 0) { - _E("invalid timeout value [%d]!", res->config_data.gov_timeout); + _E("invalid timeout value [%lf]!", res->config_data.gov_timeout); cpuhp_governor_update(res, PASS_OFF); return -EINVAL; } -- 2.7.4 From a181e6d91224d70896c746769cafefd6b545922c Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 12 Dec 2018 16:37:53 +0900 Subject: [PATCH 07/16] gdbus: Remove meaningless parameter for error description Variable arg has Gvariant* type, but format string is not used properly. Even it changed to %p properly, just print out address of Gvariant structure has no meaning. So, this patch get rid of this unnecessary information. Change-Id: I54229953dfd66c3ff3219cb08d578472cd1ddb60 Signed-off-by: Dongwoo Lee --- src/core/gdbus-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/gdbus-util.c b/src/core/gdbus-util.c index d18137c..7909a7d 100644 --- a/src/core/gdbus-util.c +++ b/src/core/gdbus-util.c @@ -217,7 +217,7 @@ int pass_gdbus_send_broadcast_signal(char *path, char *interface, char *method, ret = g_dbus_connection_send_message(g_dbus_sys_conn, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err); if (!ret) { - _E("failed to broadcast [%s][%d]", method, arg); + _E("failed to broadcast [%s]", method); g_object_unref(message); return -ECOMM; } -- 2.7.4 From 516710618d64dd79d90fceb8e4b524b0df22c07b Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 12 Dec 2018 16:39:25 +0900 Subject: [PATCH 08/16] thermal: Add explicit type casting for string output Change-Id: Ide6cf245737097dc9907943a5b9c04ed1de8b4b7 Signed-off-by: Dongwoo Lee --- src/thermal/thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 2bab82d..a123ef9 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -221,7 +221,7 @@ static int thermal_notifier_cb(void *data, void *user_data) /* If there is no available thermal scenario, just return */ if (i >= g_thermal->num) { - _I("Not supported \'%s\' scenario", data); + _I("Not supported \'%s\' scenario", (char*)data); return 0; } -- 2.7.4 From b2de5a6599c40fcd6c53f315e48f94994f0823ce Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 12 Dec 2018 16:12:06 +0900 Subject: [PATCH 09/16] pass: Fix type-check errors on dlog output Change-Id: Ib465e5b2a0f77ec81943bebcbd38d4e31a688172 Signed-off-by: Dongwoo Lee --- src/pass/pass-parser.c | 2 +- src/pass/pass-resmon.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pass/pass-parser.c b/src/pass/pass-parser.c index 2828743..47b38d0 100644 --- a/src/pass/pass-parser.c +++ b/src/pass/pass-parser.c @@ -870,7 +870,7 @@ int pass_get_each_resource_config(struct pass_resource *res, char *path) return -EINVAL; if (pmqos->state == PASS_UNUSED) - _W("%s don't include the list of pass-scenario\n"); + _W("don't include the list of pass-scenario\n"); else if (pmqos->state == PASS_OFF) _I("cannot use pass-scenario"); diff --git a/src/pass/pass-resmon.c b/src/pass/pass-resmon.c index 7b644ce..35fc30c 100644 --- a/src/pass/pass-resmon.c +++ b/src/pass/pass-resmon.c @@ -738,7 +738,7 @@ int pass_resmon_unregister_uevent(struct pass_resource *res, monitor = resmon_find_monitor(&res->resmon, RESMON_UEVENT, src_type); if (!monitor) { - _E("failed to find monitor (res_name: %d, type: 0x%x)\n", + _E("failed to find monitor (res_name: %s, type: 0x%x)\n", res->config_data.res_name, src_type); return -EINVAL; } @@ -746,7 +746,7 @@ int pass_resmon_unregister_uevent(struct pass_resource *res, /* Delete uevent-based resource monitor */ ret = resmon_uevent_delete(monitor); if (ret < 0) { - _E("failed to delete monitor (res_name: %d, type: 0x%x)\n", + _E("failed to delete monitor (res_name: %s, type: 0x%x)\n", res->config_data.res_name, src_type); } -- 2.7.4 From d76e0bf36852527c98ea0aea2d718a12bc4cd30f Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 17 Dec 2018 11:06:10 +0900 Subject: [PATCH 10/16] pass: pmqos: print int64_t type on 32/64bit architecture properly Since int64_t is translating into 'long long int' on 32bit, but 'long int' on 64bit. So, "%lld" cannot satisfying both architectures. This patch uses PRId64 instead of "%lld" to adjust the format string as following the corresponding architecture. Change-Id: Iac0d14ac1ccff7b6fba187fc3205e2c81271727b Signed-off-by: Dongwoo Lee --- src/pass/pass-pmqos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pass/pass-pmqos.c b/src/pass/pass-pmqos.c index ceea62a..319e4d6 100644 --- a/src/pass/pass-pmqos.c +++ b/src/pass/pass-pmqos.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -182,7 +183,7 @@ static int pmqos_notifier_cb(void *data, void *user_data) pmqos->scenarios[index].pmqos.locked_time = get_time_ms(); } else { - _I("UnLock '%s' scenario for '%s' resource (%lldms)\n", + _I("UnLock '%s' scenario for '%s' resource (%"PRId64"ms)\n", name, config_data->res_name, (get_time_ms() - pmqos->scenarios[index].pmqos.locked_time)); -- 2.7.4 From ddd66f1bd3d13cbdc88410925b153becefa00d8b Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 11 Apr 2019 16:52:36 +0900 Subject: [PATCH 11/16] pass: core: Remove unused structure Since commit 261812a0492a, struct device_ops default_ops is not used anymore. This patch removes it to prevent build warning. Change-Id: I933adf899125ff0f6b078cffb06f7fd6d0ec99ca Fixes: 261812a0492a ("core: Remove unneeded codesa") Signed-off-by: Dongwoo Lee --- src/core/devices.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/devices.c b/src/core/devices.c index 0e7b969..296c047 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -23,10 +23,6 @@ #include #include -static const struct device_ops default_ops = { - .name = "default-ops", -}; - static GList *dev_head; void add_device(const struct device_ops *dev) -- 2.7.4 From a33200bbbe14a6a33e935e6a71408c3872dbdc09 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 11 Apr 2019 16:44:13 +0900 Subject: [PATCH 12/16] pass: Change DBUS interface of thermal monitor This patch changes DBUS interface as following thermal interface standard like below: - Interface: org.tizen.system.thermal - Path: /Org/Tizen/System/Thermal - Broadcast name: CoolDownModeChanged Change-Id: Iedf5a1d78536a10829d37e84fadae0e51706f886 Signed-off-by: Dongwoo Lee --- include/pass/gdbus-definition.h | 6 +++--- include/pass/gdbus-util.h | 4 ++-- scripts/pass-thermal.conf | 6 +++--- scripts/thermal-dbus.xml | 4 ++-- src/core/gdbus-util.c | 6 +++--- src/thermal/thermal.c | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/pass/gdbus-definition.h b/include/pass/gdbus-definition.h index cca8b3f..16da516b6 100644 --- a/include/pass/gdbus-definition.h +++ b/include/pass/gdbus-definition.h @@ -35,11 +35,11 @@ #define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" #define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" -#define DBUS_THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" -#define DBUS_THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" +#define DBUS_THERMAL_INTERFACE "org.tizen.system.thermal" +#define DBUS_THERMAL_PATH "/Org/Tizen/System/Thermal" #define DBUS_THERMAL_I_START_HANDLER "handle_start" #define DBUS_THERMAL_I_STOP_HANDLER "handle_stop" -#define DBUS_THERMAL_METHOD "thermal_scenario" +#define DBUS_THERMAL_SIGNAL "CoolDownModeChanged" /* Dbus definition for systemd */ #define SYSTEMD_DBUS_NAME "org.freedesktop.systemd1" diff --git a/include/pass/gdbus-util.h b/include/pass/gdbus-util.h index 130e237..c85c228 100644 --- a/include/pass/gdbus-util.h +++ b/include/pass/gdbus-util.h @@ -54,8 +54,8 @@ SystemPassCore *pass_gdbus_get_instance_core(void); void pass_gdbus_put_instance_core(SystemPassCore **instance); SystemPassPmqos *pass_gdbus_get_instance_pmqos(void); void pass_gdbus_put_instance_pmqos(SystemPassPmqos **instance); -SystemPassMonitorThermal *pass_gdbus_get_instance_thermal(void); -void pass_gdbus_put_instance_thermal(SystemPassMonitorThermal **instance); +SystemThermal *pass_gdbus_get_instance_thermal(void); +void pass_gdbus_put_instance_thermal(SystemThermal **instance); int pass_gdbus_get_system_connection(void); void pass_gdbus_put_system_connection(void); diff --git a/scripts/pass-thermal.conf b/scripts/pass-thermal.conf index ad0f02d..bc0c656 100644 --- a/scripts/pass-thermal.conf +++ b/scripts/pass-thermal.conf @@ -9,11 +9,11 @@ thermal_number_of_scenario=4 #name=ReleaseAction #support=yes [thermal.scenario0] -name=ReleaseAction +name=Release support=yes [thermal.scenario1] -name=WarningAction +name=Warning support=yes [thermal.scenario2] @@ -21,5 +21,5 @@ name=LimitAction support=yes [thermal.scenario3] -name=ShutdownAction +name=Shutdown support=yes diff --git a/scripts/thermal-dbus.xml b/scripts/thermal-dbus.xml index 0b4b6f1..535a33f 100644 --- a/scripts/thermal-dbus.xml +++ b/scripts/thermal-dbus.xml @@ -1,6 +1,6 @@ - - + + diff --git a/src/core/gdbus-util.c b/src/core/gdbus-util.c index 7909a7d..e7774e2 100644 --- a/src/core/gdbus-util.c +++ b/src/core/gdbus-util.c @@ -253,12 +253,12 @@ void pass_gdbus_put_instance_pmqos(SystemPassPmqos **instance) put_instance((gpointer *)instance); } -SystemPassMonitorThermal *pass_gdbus_get_instance_thermal(void) +SystemThermal *pass_gdbus_get_instance_thermal(void) { - return system_pass_monitor_thermal_skeleton_new(); + return system_thermal_skeleton_new(); } -void pass_gdbus_put_instance_thermal(SystemPassMonitorThermal **instance) +void pass_gdbus_put_instance_thermal(SystemThermal **instance) { put_instance((gpointer *)instance); } diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index a123ef9..76207c3 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -44,7 +44,7 @@ * @brief Global instance indicating the Thermal Monitor D-Bus interface * for PASS (Power Aware System Service) */ -static SystemPassMonitorThermal *g_gdbus_instance = NULL; +static SystemThermal *g_gdbus_instance = NULL; /** * @brief Global instance indicating Thermal Monitor feature for PASS @@ -128,7 +128,7 @@ static int thermal_init_done(void *data, void *user_data) * @param [in] user_data Not used * @return @c true if success, otherwise @c false if fail */ -static gboolean dbus_cb_thermal_start(SystemPassMonitorThermal *obj, +static gboolean dbus_cb_thermal_start(SystemThermal *obj, GDBusMethodInvocation *invoc, gpointer user_data) { int ret = 0; @@ -157,7 +157,7 @@ static gboolean dbus_cb_thermal_start(SystemPassMonitorThermal *obj, * @param [in] user_data Unused parameter * @return @c true if success, otherwise @c false if fail */ -static gboolean dbus_cb_thermal_stop(SystemPassMonitorThermal *obj, +static gboolean dbus_cb_thermal_stop(SystemThermal *obj, GDBusMethodInvocation *invoc, gpointer user_data) { if (!g_thermal) @@ -229,7 +229,7 @@ static int thermal_notifier_cb(void *data, void *user_data) gvar = g_variant_new("(s)", data); ret = pass_gdbus_send_broadcast_signal(DBUS_THERMAL_PATH, DBUS_THERMAL_INTERFACE, - DBUS_THERMAL_METHOD, + DBUS_THERMAL_SIGNAL, gvar); if (ret < 0) { _E("failed to send broadcast signal of thermal monitor(%d)\n", -- 2.7.4 From 8b38522102eb8249ea6f9fd3d81360554bfb2102 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 22 May 2019 17:37:04 +0900 Subject: [PATCH 13/16] Modify pass.conf to add org.tizen.system.thermal Change-Id: Idb32f28286f7a4aa8fb44539b0e818c6c711cee1 Signed-off-by: Hyotaek Shim --- scripts/pass.conf | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/pass.conf b/scripts/pass.conf index e622253..de325a5 100644 --- a/scripts/pass.conf +++ b/scripts/pass.conf @@ -1,20 +1,18 @@ - + + - - - - - + + - + -- 2.7.4 From 79ab724716daa0aa08d17e123f53ccdeab4ecf71 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 27 May 2019 16:07:05 +0900 Subject: [PATCH 14/16] pass: thermal: Correct thermal action names This patch correct thermal action names in comments in order to match into previous changes. Change-Id: I7931ddc9dc42bf364cb9f020741d063402004c33 Signed-off-by: Dongwoo Lee --- scripts/pass-thermal.conf | 2 +- src/thermal/thermal-parser.c | 6 +++--- src/thermal/thermal.c | 4 ++-- src/thermal/thermal.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/pass-thermal.conf b/scripts/pass-thermal.conf index bc0c656..f15ad2c 100644 --- a/scripts/pass-thermal.conf +++ b/scripts/pass-thermal.conf @@ -6,7 +6,7 @@ thermal_number_of_scenario=4 # describe the scenario section as follows #[Scenario0] -#name=ReleaseAction +#name=Release #support=yes [thermal.scenario0] name=Release diff --git a/src/thermal/thermal-parser.c b/src/thermal/thermal-parser.c index 7dfdaf1..58df42e 100644 --- a/src/thermal/thermal-parser.c +++ b/src/thermal/thermal-parser.c @@ -23,8 +23,8 @@ * @brief Parse the supported thermal scenario information from * /etc/pass/pass-thermal.conf configuration. * - /etc/pass/pass-thermal.conf contains the list and information - * for supported thermal scenarios. For example, ReleaseAction, - * WarningAction, LimitAction and ShutdownAction. + * for supported thermal scenarios. For example, Release, + * Warning, LimitAction and Shutdown. * @ingroup COM_POWER_MGNT */ @@ -113,7 +113,7 @@ static int thermal_parse_scenario(struct parse_result *result, void *user_data, /** * @brief Parse configuration to get information of supported scenarios - * for Thermal Monitor such as ReleaseAction, WarningAction. + * for Thermal Monitor such as Release, Warning. * @param [in] result Parsed raw data from configuration * @param [in] user_data Instance for each scenario * @return @c 0 on success, otherwise error value diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 76207c3..cf823f5 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -21,7 +21,7 @@ * @brief Provide Thermal Monitor external D-bus interface and verify * whether the thermal scenarios are supported or not and then * send broadcasting D-bus signal with the decided thermal - * scenario like ReleseAction through D-bus interface. + * scenario like Release through D-bus interface. * @ingroup COM_POWER_MGNT */ @@ -194,7 +194,7 @@ static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = { * @brief Send broadcasting signal with the decided scenario name from * pass-thermal before checking whether the scenario is supported * or not.. - * @param [in] data Scenario name like ReleaseAction, WarningAction + * @param [in] data Scenario name like Release, Warning * @param [in] user_data Unused parameter */ static int thermal_notifier_cb(void *data, void *user_data) diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h index fd8295c..836fa20 100644 --- a/src/thermal/thermal.h +++ b/src/thermal/thermal.h @@ -23,7 +23,7 @@ * @brief Provide Thermal Monitor external D-bus interface and verify * whether the thermal scenarios are supported or not and then * send broadcasting D-bus signal with the decided thermal - * scenario like ReleseAction through D-bus interface. + * scenario like Release through D-bus interface. * @ingroup COM_POWER_MGNT */ -- 2.7.4 From 3ec20dd0ab16e212ad4bcf64fa04602287e30643 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 30 Apr 2019 13:11:39 +0900 Subject: [PATCH 15/16] pass: thermal: Prevent memory leakage To prevent memory leakage, free allocated memory on error case. Change-Id: If0c94bc23e47eafff594afb435b909b544708ac3 Signed-off-by: Dongwoo Lee --- src/thermal/thermal.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index cf823f5..3937be1 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -103,13 +103,18 @@ static int thermal_init_done(void *data, void *user_data) ret = thermal_get_scenario(THERMAL_CONF_PATH, g_thermal); if (ret < 0) { _E("failed to get Thermal Monitor scenario\n"); + free(g_thermal); + g_thermal = NULL; return ret; } if (!g_thermal->support || g_thermal->num <= 0) { ret = thermal_put_scenario(g_thermal); - if (ret < 0) - _E("failed to pet Thermal Monitor scenario\n"); + if (ret < 0) { + _E("failed to put Thermal Monitor scenario\n"); + free(g_thermal); + g_thermal = NULL; + } return ret; } -- 2.7.4 From e60cc99d1374302eb3a1f38982d8b80d98c660c0 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 23 May 2019 15:56:18 +0900 Subject: [PATCH 16/16] pass: thermal: add separate dbus for thermal monitor This patch adds separate dbus for thermal monitor, and it owns well-know name as "org.tizen.system.thermal". Change-Id: I5a4126e5debb597e7cdb2e722772a4966eb329e0 Signed-off-by: Dongwoo Lee --- include/pass/gdbus-definition.h | 7 ++++ include/pass/gdbus-util.h | 10 +++--- src/core/gdbus-util.c | 76 ++++++++++++++++++++++++++++------------- src/core/main.c | 6 ++-- src/pass/pass.c | 3 +- src/pmqos/pmqos.c | 3 +- src/thermal/thermal.c | 30 +++++++++++++--- 7 files changed, 97 insertions(+), 38 deletions(-) diff --git a/include/pass/gdbus-definition.h b/include/pass/gdbus-definition.h index 16da516b6..2eaaa82 100644 --- a/include/pass/gdbus-definition.h +++ b/include/pass/gdbus-definition.h @@ -19,6 +19,12 @@ #ifndef __GDBUS_DEFINITION_H__ #define __GDBUS_DEFINITION_H__ +typedef enum { + PASS_DBUS_CORE, + PASS_DBUS_THERMAL, + PASS_DBUS_MAX, +} passdbus; + /* Dbus definition for PASS */ #define DBUS_PASS_BUS_NAME "org.tizen.system.pass" #define DBUS_PASS_PATH "/Org/Tizen/System/Pass" @@ -35,6 +41,7 @@ #define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" #define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" +#define DBUS_THERMAL_BUS_NAME "org.tizen.system.thermal" #define DBUS_THERMAL_INTERFACE "org.tizen.system.thermal" #define DBUS_THERMAL_PATH "/Org/Tizen/System/Thermal" #define DBUS_THERMAL_I_START_HANDLER "handle_start" diff --git a/include/pass/gdbus-util.h b/include/pass/gdbus-util.h index c85c228..2f8e078 100644 --- a/include/pass/gdbus-util.h +++ b/include/pass/gdbus-util.h @@ -41,13 +41,13 @@ int pass_gdbus_register_systemd_startup_callback(GDBusSignalCallback cb, int pass_gdbus_unregister_systemd_startup_callback(guint id); int pass_gdbus_get_systemd_dbus_property_string(const char *iface, const char *prop, const char **value); -int pass_gdbus_export_interface(gpointer instance, const char *obj_path); -int pass_gdbus_get_name(const char *name); +int pass_gdbus_export_interface(passdbus idx, gpointer instance, const char *obj_path); +int pass_gdbus_get_name(passdbus idx, const char *name); int pass_gdbus_connect_signal(gpointer instance, int num_signals, struct pass_gdbus_signal_info *signal_infos); void pass_gdbus_disconnect_signal(gpointer instance, int num_signals, struct pass_gdbus_signal_info *signal_infos); -int pass_gdbus_send_broadcast_signal(char *path, char *interface, +int pass_gdbus_send_broadcast_signal(passdbus idx, char *path, char *interface, char *method, GVariant *arg); SystemPassCore *pass_gdbus_get_instance_core(void); @@ -57,6 +57,6 @@ void pass_gdbus_put_instance_pmqos(SystemPassPmqos **instance); SystemThermal *pass_gdbus_get_instance_thermal(void); void pass_gdbus_put_instance_thermal(SystemThermal **instance); -int pass_gdbus_get_system_connection(void); -void pass_gdbus_put_system_connection(void); +int pass_gdbus_get_system_connection(passdbus idx); +void pass_gdbus_put_system_connection(passdbus idx); #endif /* __GDBUS_UTIL_H__ */ diff --git a/src/core/gdbus-util.c b/src/core/gdbus-util.c index e7774e2..c2846f5 100644 --- a/src/core/gdbus-util.c +++ b/src/core/gdbus-util.c @@ -22,20 +22,21 @@ #include #include -static GDBusConnection *g_dbus_sys_conn = NULL; +static GDBusConnection *g_dbus_sys_conn[PASS_DBUS_MAX] = {NULL, }; int pass_gdbus_register_systemd_startup_callback(GDBusSignalCallback cb, gpointer user_data, guint *id) { + GDBusConnection *conn = g_dbus_sys_conn[PASS_DBUS_CORE]; guint tmp_id; - if (g_dbus_sys_conn == NULL) { + if (conn == NULL) { _E("cannot get the dbus connection " "to the system message bus\n"); return -ENOSYS; } - tmp_id = g_dbus_connection_signal_subscribe(g_dbus_sys_conn, + tmp_id = g_dbus_connection_signal_subscribe(conn, SYSTEMD_DBUS_NAME, SYSTEMD_DBUS_IFACE_MANAGER, "StartupFinished", @@ -55,7 +56,9 @@ int pass_gdbus_register_systemd_startup_callback(GDBusSignalCallback cb, int pass_gdbus_unregister_systemd_startup_callback(guint id) { - if (g_dbus_sys_conn == NULL) { + GDBusConnection *conn = g_dbus_sys_conn[PASS_DBUS_CORE]; + + if (conn == NULL) { _E("cannot get the dbus connection " "to the system message bus\n"); return -ENOSYS; @@ -64,7 +67,7 @@ int pass_gdbus_unregister_systemd_startup_callback(guint id) if (!id) return -EINVAL; - g_dbus_connection_signal_unsubscribe(g_dbus_sys_conn, id); + g_dbus_connection_signal_unsubscribe(conn, id); return 0; } @@ -72,17 +75,18 @@ int pass_gdbus_unregister_systemd_startup_callback(guint id) int pass_gdbus_get_systemd_dbus_property_string(const char *iface, const char *prop, const char **value) { + GDBusConnection *conn = g_dbus_sys_conn[PASS_DBUS_CORE]; GError *error = NULL; GVariant *reply; GVariant *result; - if (g_dbus_sys_conn == NULL) { + if (conn == NULL) { _E("cannot get the dbus connection " "to the system message bus\n"); return -ENOSYS; } - reply = g_dbus_connection_call_sync(g_dbus_sys_conn, + reply = g_dbus_connection_call_sync(conn, SYSTEMD_DBUS_NAME, SYSTEMD_DBUS_OBJECT_PATH, SYSTEMD_DBUS_IFACE_FOR_PROPS, @@ -110,11 +114,17 @@ int pass_gdbus_get_systemd_dbus_property_string(const char *iface, return 0; } -int pass_gdbus_export_interface(gpointer instance, const char *obj_path) +int pass_gdbus_export_interface(passdbus idx, gpointer instance, + const char *obj_path) { gboolean ret; - if (g_dbus_sys_conn == NULL) { + if (idx >= PASS_DBUS_MAX) { + _E("Invalid DBUS connection: %d\n", idx); + return -EINVAL; + } + + if (g_dbus_sys_conn[idx] == NULL) { _E("cannot get the dbus connection " "to the system message bus\n"); return -ENOSYS; @@ -122,7 +132,7 @@ int pass_gdbus_export_interface(gpointer instance, const char *obj_path) ret = g_dbus_interface_skeleton_export( G_DBUS_INTERFACE_SKELETON(instance), - g_dbus_sys_conn, + g_dbus_sys_conn[idx], obj_path, NULL); if (ret == TRUE) @@ -131,11 +141,16 @@ int pass_gdbus_export_interface(gpointer instance, const char *obj_path) return -1; } -int pass_gdbus_get_name(const char *name) +int pass_gdbus_get_name(passdbus idx, const char *name) { guint id; - id = g_bus_own_name_on_connection(g_dbus_sys_conn, name, + if (idx >= PASS_DBUS_MAX) { + _E("Invalid DBUS connection: %d\n", idx); + return -EINVAL; + } + + id = g_bus_own_name_on_connection(g_dbus_sys_conn[idx], name, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); if (id == 0) @@ -188,8 +203,8 @@ void pass_gdbus_disconnect_signal(gpointer instance, int num_signals, } } -int pass_gdbus_send_broadcast_signal(char *path, char *interface, char *method, - GVariant *arg) +int pass_gdbus_send_broadcast_signal(passdbus idx, char *path, + char *interface, char *method, GVariant *arg) { GDBusMessage *message = NULL; GError *err = NULL; @@ -200,7 +215,12 @@ int pass_gdbus_send_broadcast_signal(char *path, char *interface, char *method, return -EINVAL; } - if (!g_dbus_sys_conn) { + if (idx >= PASS_DBUS_MAX) { + _E("Invalid DBUS connection: %d\n", idx); + return -EINVAL; + } + + if (!g_dbus_sys_conn[idx]) { _E("cannot get the dbus connection to system message bus\n"); return -ENOSYS; } @@ -214,7 +234,7 @@ int pass_gdbus_send_broadcast_signal(char *path, char *interface, char *method, g_dbus_message_set_body(message, arg); /* Send broadcast signal */ - ret = g_dbus_connection_send_message(g_dbus_sys_conn, message, + ret = g_dbus_connection_send_message(g_dbus_sys_conn[idx], message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err); if (!ret) { _E("failed to broadcast [%s]", method); @@ -263,13 +283,18 @@ void pass_gdbus_put_instance_thermal(SystemThermal **instance) put_instance((gpointer *)instance); } -int pass_gdbus_get_system_connection(void) +int pass_gdbus_get_system_connection(passdbus idx) { GError *error = NULL; - g_dbus_sys_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, + if (idx >= PASS_DBUS_MAX) { + _E("Invalid connection: %d\n", idx); + return -EINVAL; + } + + g_dbus_sys_conn[idx] = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (g_dbus_sys_conn == NULL) { + if (g_dbus_sys_conn[idx] == NULL) { _E("cannot connect to the system message bus: %s\n", error->message); return -ENOSYS; @@ -278,10 +303,15 @@ int pass_gdbus_get_system_connection(void) return 0; } -void pass_gdbus_put_system_connection(void) +void pass_gdbus_put_system_connection(passdbus idx) { - if (g_dbus_sys_conn) { - g_object_unref(g_dbus_sys_conn); - g_dbus_sys_conn = NULL; + if (idx >= PASS_DBUS_MAX) { + _E("Invalid DBUS connection: %d\n", idx); + return; + } + + if (g_dbus_sys_conn[idx]) { + g_object_unref(g_dbus_sys_conn[idx]); + g_dbus_sys_conn[idx] = NULL; } } diff --git a/src/core/main.c b/src/core/main.c index b86224d..46944a4 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -95,7 +95,7 @@ static int late_init(void) signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); - ret = pass_gdbus_get_name(DBUS_PASS_BUS_NAME); + ret = pass_gdbus_get_name(PASS_DBUS_CORE, DBUS_PASS_BUS_NAME); if (ret < 0) return ret; @@ -117,7 +117,7 @@ static int late_init(void) int main(int argc, char **argv) { g_mainloop = g_main_loop_new(NULL, FALSE); - pass_gdbus_get_system_connection(); + pass_gdbus_get_system_connection(PASS_DBUS_CORE); devices_init(NULL); if (late_init() < 0) @@ -126,7 +126,7 @@ int main(int argc, char **argv) g_main_loop_run(g_mainloop); devices_exit(NULL); - pass_gdbus_put_system_connection(); + pass_gdbus_put_system_connection(PASS_DBUS_CORE); g_main_loop_unref(g_mainloop); return 0; diff --git a/src/pass/pass.c b/src/pass/pass.c index 304df55..0c5abca 100644 --- a/src/pass/pass.c +++ b/src/pass/pass.c @@ -513,7 +513,8 @@ static int pass_probe(void *data) goto out; } - ret = pass_gdbus_export_interface(g_gdbus_instance, DBUS_CORE_PATH); + ret = pass_gdbus_export_interface(PASS_DBUS_CORE, + g_gdbus_instance, DBUS_CORE_PATH); if (ret < 0) { _E("cannot export the dbus interface '%s' " "at the object path '%s'\n", diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 7ffd98b..edb1599 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -611,7 +611,8 @@ static int pmqos_probe(void *data) goto out; } - ret = pass_gdbus_export_interface(g_gdbus_instance, DBUS_PMQOS_PATH); + ret = pass_gdbus_export_interface(PASS_DBUS_CORE, + g_gdbus_instance, DBUS_PMQOS_PATH); if (ret < 0) { _E("cannot export the dbus interface '%s' " "at the object path '%s'\n", diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 3937be1..9669d8d 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -232,7 +232,8 @@ static int thermal_notifier_cb(void *data, void *user_data) /* If there is available thermal scenario, send the broadcast signal */ gvar = g_variant_new("(s)", data); - ret = pass_gdbus_send_broadcast_signal(DBUS_THERMAL_PATH, + ret = pass_gdbus_send_broadcast_signal(PASS_DBUS_THERMAL, + DBUS_THERMAL_PATH, DBUS_THERMAL_INTERFACE, DBUS_THERMAL_SIGNAL, gvar); @@ -271,6 +272,8 @@ static void thermal_exit(void *data) ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); pass_gdbus_put_instance_thermal(&g_gdbus_instance); + pass_gdbus_put_system_connection(PASS_DBUS_THERMAL); + thermal_free(); } @@ -286,12 +289,26 @@ static int thermal_probe(void *data) { int ret = 0; + ret = pass_gdbus_get_system_connection(PASS_DBUS_THERMAL); + if (ret < 0) { + _E("Failed to get system connection for thermal"); + return -ENOENT; + } + + ret = pass_gdbus_get_name(PASS_DBUS_THERMAL, DBUS_THERMAL_BUS_NAME); + if (ret < 0) { + _E("Failed to own dbus name '%s'\n", DBUS_THERMAL_BUS_NAME); + ret = -EINVAL; + goto out; + } + /* Initialize the d-bus interface for Thermal Monitor */ g_gdbus_instance = pass_gdbus_get_instance_thermal(); if (!g_gdbus_instance) { _E("failed to get a dbus instance for the %s interface\n", DBUS_THERMAL_INTERFACE); - return -ENOSYS; + ret = -ENOSYS; + goto out; } ret = pass_gdbus_connect_signal(g_gdbus_instance, @@ -300,10 +317,11 @@ static int thermal_probe(void *data) _E("failed to register callbacks as the dbus method invocation " "handlers\n"); ret = -ENOSYS; - goto out; + goto out_put_instance; } - ret = pass_gdbus_export_interface(g_gdbus_instance, DBUS_THERMAL_PATH); + ret = pass_gdbus_export_interface(PASS_DBUS_THERMAL, + g_gdbus_instance, DBUS_THERMAL_PATH); if (ret < 0) { _E("failed to export the dbus interface '%s' " "at the object path '%s'\n", @@ -343,8 +361,10 @@ out_booting_done: out_disconnect: pass_gdbus_disconnect_signal(g_gdbus_instance, ARRAY_SIZE(g_gdbus_signal_infos), g_gdbus_signal_infos); -out: +out_put_instance: pass_gdbus_put_instance_thermal(&g_gdbus_instance); +out: + pass_gdbus_put_system_connection(PASS_DBUS_THERMAL); return ret; } -- 2.7.4