diff options
author | Youngjae Cho <y0.cho@samsung.com> | 2020-09-07 17:07:27 +0900 |
---|---|---|
committer | Hyotaek Shim <hyotaek.shim@samsung.com> | 2020-09-08 04:51:16 +0000 |
commit | a378ebc73c3ff79fcaf2eb697bbdd78136f73318 (patch) | |
tree | 82bb363a5f4c01a37ac55905df6b4469bd27b696 | |
parent | 977280625f0596cdf2940743205f57298f4bc7ed (diff) | |
download | resourced-tizen_6.0_hotfix.tar.gz resourced-tizen_6.0_hotfix.tar.bz2 resourced-tizen_6.0_hotfix.zip |
Fix svace issuetizen_6.0.m2_releasesubmit/tizen_6.0_hotfix/20201103.114805submit/tizen_6.0_hotfix/20201102.192505submit/tizen_6.0/20201029.205105submit/tizen/20200910.050828accepted/tizen/unified/20200911.043144accepted/tizen/6.0/unified/hotfix/20201103.002008accepted/tizen/6.0/unified/20201030.114030tizen_6.0_hotfixaccepted/tizen_6.0_unified_hotfix
In addition to fix svace issue,
change yoda conditions in cpu-sched.c to usual style.
Change-Id: Ifde1796c2bdfbb2893505ec3365036068e454d75
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r-- | src/cpu/cpu-sched.c | 77 | ||||
-rw-r--r-- | src/dedup/dedup.c | 2 | ||||
-rw-r--r-- | src/swap/fileswap.c | 4 | ||||
-rw-r--r-- | src/swap/swap.c | 10 | ||||
-rw-r--r-- | src/swap/zswap.c | 4 |
5 files changed, 48 insertions, 49 deletions
diff --git a/src/cpu/cpu-sched.c b/src/cpu/cpu-sched.c index df718df8..16332c45 100644 --- a/src/cpu/cpu-sched.c +++ b/src/cpu/cpu-sched.c @@ -60,7 +60,7 @@ static bool cpu_sched_is_cpuset_mounted() bool ret = false; f = fopen(MOUNTS_PATH, "r"); - if (NULL == f) { + if (f == NULL) { _E("cpu-sched: could not open " MOUNTS_PATH); return ret; } @@ -69,7 +69,7 @@ static bool cpu_sched_is_cpuset_mounted() if (sscanf(buf, "%*s %127s %*s %127s %*d %*d", mountpoint, opts) != 2) continue; - if (!strcmp(mountpoint, CPUSET_CGROUP) && NULL != strstr(opts, "cpuset")) { + if (!strcmp(mountpoint, CPUSET_CGROUP) && strstr(opts, "cpuset") != NULL) { ret = true; break; } @@ -118,7 +118,7 @@ static int cpu_sched_init_cgroup(struct cpu_sched *cs) struct coreset *c; _D("cpu-sched: init cgroup subsystem"); - if (false == cpu_sched_is_cpuset_mounted()) { + if (cpu_sched_is_cpuset_mounted() == false) { r = cgroup_make_subdir(DEFAULT_CGROUP, "cpuset", NULL); if (r < 0) { _E("failed to make cpuset cgroup"); @@ -154,7 +154,7 @@ static int cpu_sched_new_core(struct coreset *set, int core_id) _D("cpu-sched: new core %d for set %s", core_id, set->name); c = (struct core *)calloc(1, sizeof *c); - if (NULL == c) { + if (c == NULL) { _E("cpu-sched: could not allocate memory for core struct"); return RESOURCED_ERROR_FAIL; } @@ -166,14 +166,19 @@ static int cpu_sched_new_core(struct coreset *set, int core_id) } /* free memory allocated in coreset structure */ -static void cpu_sched_free_cpuset(struct coreset *set) +static void cpu_sched_free_cpuset(struct coreset **c) { - if (NULL != set->cores) + struct coreset *set = *c; + + if (set->cores != NULL) g_slist_free_full(set->cores, free); set->cores = NULL; free(set->name); set->name = NULL; + + free(set); + *c = NULL; } /* free memory allocated in coreset structure and the structure */ @@ -183,8 +188,7 @@ static void cpu_sched_free_cpuset_full(void *data) assert(set); - cpu_sched_free_cpuset(set); - free(set); + cpu_sched_free_cpuset(&set); } /* parse config for specific coreset line */ @@ -201,10 +205,10 @@ static int cpu_sched_parse_cpuset(struct coreset *set, char *value) ptr = strtok_r(value, ",", &saveptr); while (ptr) { - if (NULL == strstr(ptr, "-")) { /* single value */ + if (strstr(ptr, "-") == NULL) { /* single value */ r = sscanf(ptr, "%d", &min); if (r == 1 && min >= 0) { - if (RESOURCED_ERROR_NONE != cpu_sched_new_core(set, min)) + if (cpu_sched_new_core(set, min) != RESOURCED_ERROR_NONE) goto parse_cpuset_fail; } else { _E("cpu-sched: error parsing cpuset (%s)", ptr); @@ -214,7 +218,7 @@ static int cpu_sched_parse_cpuset(struct coreset *set, char *value) r = sscanf(ptr, "%d-%d", &min, &max); if (r == 2 && min >= 0 && max >= 0 && max > min) { for (int i = min; i <= max; i++) { - if (RESOURCED_ERROR_NONE != cpu_sched_new_core(set, i)) + if (cpu_sched_new_core(set, i) != RESOURCED_ERROR_NONE) goto parse_cpuset_fail; } } else { @@ -228,7 +232,7 @@ static int cpu_sched_parse_cpuset(struct coreset *set, char *value) } return RESOURCED_ERROR_NONE; parse_cpuset_fail: - cpu_sched_free_cpuset(set); + cpu_sched_free_cpuset(&set); return RESOURCED_ERROR_FAIL; } @@ -238,20 +242,23 @@ static int load_config(struct parse_result *result, void *user_data) assert(data); - int ret = RESOURCED_ERROR_OUT_OF_MEMORY; bool is_fg = !strcmp(result->name, CPU_SCHED_FG_NAME); char *name = strdup(result->name); + if (name == NULL) + return RESOURCED_ERROR_OUT_OF_MEMORY; + struct coreset *c = (struct coreset *)calloc(1, sizeof *c); - if (NULL == c || NULL == name) - goto err_out; + if (c == NULL) { + free(name); + return RESOURCED_ERROR_OUT_OF_MEMORY; + } c->name = name; if (cpu_sched_parse_cpuset(c, result->value) < 0) { _E("cpu-sched parse %s coreset: could not parse", result->name); - ret = RESOURCED_ERROR_FAIL; - goto err_out; + return RESOURCED_ERROR_FAIL; } if (is_fg) @@ -260,11 +267,6 @@ static int load_config(struct parse_result *result, void *user_data) data->apps = g_slist_append(data->apps, c); return RESOURCED_ERROR_NONE; - -err_out: - free(c); - free(name); - return ret; } static int cpu_sched_parse_config(struct cpu_sched *data) @@ -294,7 +296,7 @@ static int cpu_sched_write_coreset(struct coreset *set) r = 0; gslist_for_each_item(i, set->cores) { c = (struct core *)i->data; - if (NULL == c || false == c->on) + if (c == NULL || c->on == false) continue; r += snprintf(coreset + r, sizeof coreset - r, "%d,", c->id); @@ -315,12 +317,12 @@ static int cpu_sched_cpu_on_for_coreset(struct coreset *set, int core_id) assert(set); assert(core_id >= 0); - if (NULL == set->cores) + if (set->cores == NULL) return 0; gslist_for_each_item(i, set->cores) { c = (struct core *)i->data; - if (NULL == c || c->id != core_id) + if (c == NULL || c->id != core_id) continue; _D("cpu-sched: core %d on for coreset %s", core_id, set->name); @@ -329,7 +331,7 @@ static int cpu_sched_cpu_on_for_coreset(struct coreset *set, int core_id) break; } - if (false == refresh) + if (refresh == false) return 0; return cpu_sched_write_coreset(set); @@ -344,12 +346,12 @@ static int cpu_sched_cpu_off_for_coreset(struct coreset *set, int core_id) assert(set); assert(core_id >= 0); - if (NULL == set->cores) + if (set->cores == NULL) return 0; gslist_for_each_item(i, set->cores) { c = (struct core *)i->data; - if (NULL == c || c->id != core_id) + if (c == NULL || c->id != core_id) continue; _D("cpu-sched: core %d off for coreset %s", core_id, set->name); @@ -358,7 +360,7 @@ static int cpu_sched_cpu_off_for_coreset(struct coreset *set, int core_id) break; } - if (false == refresh) + if (refresh == false) return 0; return cpu_sched_write_coreset(set); @@ -443,7 +445,7 @@ static bool cpu_sched_is_static_app(const char *appid) if (!c) return false; - if (false == c->disclaimer_shown) { + if (c->disclaimer_shown == false) { _D("cpu-sched: appid %s is statically configured - not subject to cpuset change", appid); c->disclaimer_shown = true; } @@ -459,7 +461,7 @@ static int cpu_sched_app_foreground(void *data) assert(ps); assert(ps->pai); - if (false == cs.is_initalized || true == cpu_sched_is_static_app(ps->pai->appid)) + if (cs.is_initalized == false || cpu_sched_is_static_app(ps->pai->appid) == true) return RESOURCED_ERROR_NONE; _D("cpu-sched: app %s moved to foreground; pid=%d", ps->pai->appid, ps->pid); @@ -475,7 +477,7 @@ static int cpu_sched_app_background(void *data) assert(ps); assert(ps->pai); - if (false == cs.is_initalized || true == cpu_sched_is_static_app(ps->pai->appid)) + if (cs.is_initalized == false || cpu_sched_is_static_app(ps->pai->appid) == true) return RESOURCED_ERROR_NONE; _D("cpu-sched: app %s moved to background; pid=%d", ps->pai->appid, ps->pid); @@ -494,7 +496,7 @@ static int cpu_sched_app_launch(void *data) _D("cpu-sched: app launch: %s", ps->pai->appid); c = cpu_sched_find_coreset(ps->pai->appid); - if (NULL == c) + if (c == NULL) return 0; return cpu_sched_add_pid_to_cpuset(c, ps->pid); @@ -543,11 +545,8 @@ static void unregister_notifiers() static void cpu_sched_free_cpusets() { g_slist_free_full(g_steal_pointer(&cs.apps), cpu_sched_free_cpuset_full); - if (cs.fg) { - cpu_sched_free_cpuset(cs.fg); - free(cs.fg); - cs.fg = NULL; - } + if (cs.fg) + cpu_sched_free_cpuset(&cs.fg); } static void cpu_sched_check_apps() @@ -564,7 +563,7 @@ static void cpu_sched_check_apps() continue; c = cpu_sched_find_coreset(pai->appid); - if (NULL != c) { + if (c != NULL) { cpu_sched_add_pid_to_cpuset(c, pai->main_pid); continue; } diff --git a/src/dedup/dedup.c b/src/dedup/dedup.c index b43bb927..76134731 100644 --- a/src/dedup/dedup.c +++ b/src/dedup/dedup.c @@ -578,7 +578,7 @@ static int dedup_parse_config_file(void) ret = config_parse_new(DEDUP_CONF_FILE, (void*) items); if (ret < 0) { - _E("Failed to parse configuration file: %s", strerror(-ret)); + _E("Failed to parse configuration file: %d", ret); return ret; } diff --git a/src/swap/fileswap.c b/src/swap/fileswap.c index eefbd5d9..9f3f6421 100644 --- a/src/swap/fileswap.c +++ b/src/swap/fileswap.c @@ -115,7 +115,7 @@ static int swap_file_parse_config_file(void) r = config_parse_new(SWAP_CONF_FILE, (void*) items); if (r < 0) { - _E("Failed to parse configuration file: %s", strerror(-r)); + _E("Failed to parse configuration file: %d", r); return r; } @@ -134,7 +134,7 @@ static int swap_file_init(void *data) r = swap_file_parse_config_file(); if (r < 0) { - _E("Failed to parse SwapFile config: %s", strerror(-r)); + _E("Failed to parse SwapFile config: %d", r); return r; } diff --git a/src/swap/swap.c b/src/swap/swap.c index ad0e4d1f..87d67de0 100644 --- a/src/swap/swap.c +++ b/src/swap/swap.c @@ -577,7 +577,7 @@ static int swap_losetup(struct swap_module_ops *swap, crypt_type, passwd, false); if (r < 0) { - _E("Failed to setup loop: %s", strerror(-r)); + _E("Failed to setup loop: %d", r); return r; } @@ -601,8 +601,8 @@ int swap_set_file(char *filename, struct swap_module_ops *swap, char *crypt_type filename, r); return -1; } else if (r < 0) { - _E("Failed to create swap file(%s): %s", - filename, strerror(-r)); + _E("Failed to create swap file(%s): %d", + filename, r); return r; } _I("SwapFile is created: %s", filename); @@ -623,7 +623,7 @@ int swap_set_file(char *filename, struct swap_module_ops *swap, char *crypt_type _E("Failed to make swap device(%s), exit code: %d", swap->path, r); return -EBUSY; } else if (r < 0) { - _E("Failed to make swap device(%s): %s", swap->path, strerror(-r)); + _E("Failed to make swap device(%s): %d", swap->path, r); } return r; } @@ -1020,7 +1020,7 @@ static int swap_parse_config_file(void) r = config_parse_new(SWAP_CONF_FILE, (void*) items); if (r < 0) { - _E("Failed to parse configuration file: %s", strerror(-r)); + _E("Failed to parse configuration file: %d", r); return r; } diff --git a/src/swap/zswap.c b/src/swap/zswap.c index 80fc387f..daf183da 100644 --- a/src/swap/zswap.c +++ b/src/swap/zswap.c @@ -132,7 +132,7 @@ static int swap_zswap_parse_config_file(void) r = config_parse_new(SWAP_CONF_FILE, (void*) items); if (r < 0) { - _E("Failed to parse configuration file: %s", strerror(-r)); + _E("Failed to parse configuration file: %d", r); return r; } @@ -159,7 +159,7 @@ static int swap_zswap_init(void *data) r = swap_zswap_parse_config_file(); if (r < 0) { - _E("Failed to parse SwapFile config: %s", strerror(-r)); + _E("Failed to parse SwapFile config: %d", r); return r; } |