cpu_boosting: Remove assert in error handler
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 6 Feb 2025 02:30:43 +0000 (11:30 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 7 Feb 2025 07:28:41 +0000 (16:28 +0900)
Replace assert to warning or error message for safety.
This is because, assert can kill running process directly.

Change-Id: I0909151aefd53092ae4c43a633145e87f33b51a7
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-optimizer/cpu/cpu-boosting.c

index 54b02b002e6fc660d3d514f311cf22ea7c005759..06dae68c97565563358fa9396ecd3cb573ad3d8c 100644 (file)
@@ -40,6 +40,12 @@ static guint g_latest_timer_id;
 #define CPU_CONTENTION_HANDLE_TIMEOUT_MSEC 500
 #define SOCK_PATH "/run/.resourced.socket"
 
+#define CPU_BOOSTING_LEVEL_STR(level) \
+       (level == CPU_BOOSTING_LEVEL_STRONG ? "CPU_BOOSTING_LEVEL_STRONG" : \
+        level == CPU_BOOSTING_LEVEL_MEDIUM ? "CPU_BOOSTING_LEVEL_MEDIUM" : \
+        level == CPU_BOOSTING_LEVEL_WEAK ? "CPU_BOOSTING_LEVEL_WEAK" : \
+        level == CPU_BOOSTING_LEVEL_NONE ? "CPU_BOOSTING_LEVEL_NONE" : "Unknown CPU boosting level")
+
 /**
  * Information to restore CPU boosting level
  * before dealing with CPU contention
@@ -110,7 +116,10 @@ static void free_cpu_boosting_info(gpointer data)
                (struct syscommon_resourced_cpu_boosting_info *)data;
        uint32_t cpu_boosting_info_set_flag = 0;
 
-       assert(cpu_boosting_info);
+       if (cpu_boosting_info == NULL) {
+               _E("Failed to free CPU boosting info structure due to null pointer");
+               return;
+       }
 
        cpu_boosting_info_set_flag = CPU_BOOSTING_INFO_SET_REF_CNT;
        set_cpu_boosting_info(cpu_boosting_info_set_flag,
@@ -126,7 +135,10 @@ static void free_cpu_contention_handle_data(gpointer data)
        struct cpu_contention_handle_data *cpu_contention_handle_data =
                (struct cpu_contention_handle_data *)data;
 
-       assert(cpu_contention_handle_data);
+       if (cpu_contention_handle_data == NULL) {
+               _E("Failed to free cpu_contention_handle_data due to null pointer");
+               return;
+       }
 
        g_slice_free(struct cpu_contention_handle_data,
                        cpu_contention_handle_data);
@@ -147,7 +159,10 @@ static void remove_cpu_boosting_info_in_tables(int *tid)
 static void find_cpu_boosting_info_in_tables(
                struct syscommon_resourced_cpu_boosting_info **cpu_boosting_info, int *tid)
 {
-       assert(cpu_boosting_info);
+       if (cpu_boosting_info == NULL) {
+               _E("Failed to find CPU boosting info structure due to null pointer");
+               return;
+       }
 
        for (cpu_boosting_level_e cpu_boosting_level = CPU_BOOSTING_LEVEL_STRONG;
                        cpu_boosting_level < CPU_BOOSTING_LEVEL_END; cpu_boosting_level++) {
@@ -312,7 +327,10 @@ static void register_cpu_contention_handle_data(
 {
        struct cpu_contention_handle_data *cpu_contention_handle_data = NULL;
 
-       assert(input);
+       if (input == NULL) {
+               _E("CPU boosting input argument cannot be null");
+               return;
+       }
 
        /**
         * Register information to restore cpu boosting level
@@ -403,7 +421,10 @@ static gboolean cpu_boosting_governor_govern_request (gpointer user_data)
        g_source_unref(source);
 
        gslist_for_each_safe(action_list, iter, next, input) {
-               assert(input);
+               if (input == NULL) {
+                       _W("syscommon_resourced_cpu_boosting_input cannot be null");
+                       continue;
+               }
 
                register_cpu_contention_handle_data(input, cpu_boosting_level,
                                *timer_id);
@@ -829,7 +850,10 @@ destroy_input:
 static int cpu_boosting_enqueue_by_conf(void *data,
                struct syscommon_resourced_cpu_boosting_input **input)
 {
-       assert(data);
+       if (data == NULL) {
+               _E("Input argument data cannot be null");
+               return RESOURCED_ERROR_INVALID_PARAMETER;
+       }
 
        int ret;
        struct proc_status *ps = (struct proc_status *)data;
@@ -917,8 +941,9 @@ static gboolean cpu_boosting_timeout(gpointer data)
                        continue;
 
                if (!is_valid_cpu_boosting_level(cpu_boosting_info->level)) {
-                       _E("[CPU-BOOSTING] Unknown cpu boosting level (SIGABT)");
-                       assert(0);
+                       _W("[CPU-BOOSTING] Unknown cpu boosting level (%s)",
+                                       CPU_BOOSTING_LEVEL_STR(cpu_boosting_info->level));
+                       continue;
                }
 
                g_hash_table_remove(g_cpu_boosting_info_table[cpu_boosting_info->level],
@@ -1595,17 +1620,26 @@ static int cpu_boosting_init(void *data)
        for (int level = CPU_BOOSTING_LEVEL_STRONG; level < CPU_BOOSTING_LEVEL_END; level++) {
                g_cpu_boosting_info_table[level] = g_hash_table_new_full(
                                g_int_hash, g_int_equal, NULL, free_cpu_boosting_info);
-               g_assert(g_cpu_boosting_info_table[level]);
+
+               if (g_cpu_boosting_info_table[level] == NULL)
+                       _W("Global CPU boosting info table of level (%s) cannot be null",
+                                       CPU_BOOSTING_LEVEL_STR(level));
        }
 
        dest_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                        cpu_boosting_destroy_request);
-       g_assert(dest_table);
+       if (dest_table == NULL) {
+               _E("A hash table for CPU boosting inheritance cannot be null");
+               return RESOURCED_ERROR_FAIL;
+       }
 
        g_cpu_contention_handle_data_table =
                g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
                                free_cpu_contention_handle_data);
-       g_assert(g_cpu_contention_handle_data_table);
+       if (g_cpu_contention_handle_data_table == NULL) {
+               _E("A hash table for CPU governor cannot be null");
+               return RESOURCED_ERROR_FAIL;
+       }
 
        /* For the conf-based client */
        register_notifier(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, cpu_boosting_recv_from_conf);