power: Modify the code to keep code consistency 69/315969/1 accepted/tizen/7.0/unified/20240821.161631
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 9 Aug 2024 11:44:28 +0000 (20:44 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 12 Aug 2024 05:15:37 +0000 (14:15 +0900)
To keep code quality and readability,
these modifications are added.
1. Remove unofficial abbreviations in function/variable name.
2. Change void return type function to return int type.
3. Add return value checking and debug message.

Change-Id: I2bd738db09beb10cf5a79ba7d95ce2deea399595
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/power/power.c

index c63d3ed7f79029455e32c26a4d1d28e68ec23f6d..9ccf8de256ef4cefec555a10aac402a67712dc27 100644 (file)
@@ -198,26 +198,31 @@ int add_change_state_wait(pid_t pid, guint64 state)
        return 0;
 }
 
-static void remove_csw_element_from_waiting_list(struct proc_info* pi, guint64 state)
+static int remove_change_state_wait_element_from_waiting_list(struct proc_info* proc_info, guint64 state)
 {
        GList *iterator = transition_context.waitings;
 
+       if (!proc_info)
+               return -EINVAL;
+
        while (iterator != NULL) {
-               struct change_state_wait *csw = (struct change_state_wait *)iterator->data;
-               if (csw->pi->pid == pi->pid && csw->state == state) {
+               struct change_state_wait *change_state_wait = (struct change_state_wait *)iterator->data;
+               if (change_state_wait->pi->pid == proc_info->pid && change_state_wait->state == state) {
                        transition_context.waitings = g_list_remove_link(transition_context.waitings, iterator);
                        free(g_steal_pointer(&iterator->data));
                        g_list_free(iterator);
-                       return;
+                       break;
                }
                iterator = g_list_next(iterator);
        }
+       return 0;
 }
 
 void remove_change_state_wait(pid_t pid, guint64 state)
 {
        struct proc_info *pi = NULL;
        GList *l = NULL;
+       int ret = 0;
 
        l = g_list_find_custom(proc_list, &pid, find_pi_by_pid);
        if (!l)
@@ -231,7 +236,12 @@ void remove_change_state_wait(pid_t pid, guint64 state)
        _D("pid=%d(%s) removed csw for %#"PRIx64, pi->pid, pi->comm, state);
 
        pi->state_bitmap &= ~state;
-       remove_csw_element_from_waiting_list(pi, state);
+       ret = remove_change_state_wait_element_from_waiting_list(pi, state);
+       if (ret < 0) {
+               _E("Failed to remove change state wait element from waiting list");
+               return;
+       }
+
        if (pi->state_bitmap == 0) {
                proc_list = g_list_remove_link(proc_list, l);
                free(g_steal_pointer(&l->data));