cpu-boosting-monitor: Check return value of eventfd_write and remove useless code 18/298718/4 accepted/tizen/unified/20230914.100402
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 13 Sep 2023 01:51:39 +0000 (10:51 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 13 Sep 2023 06:10:54 +0000 (15:10 +0900)
Check return value of eventfd_write and remove eventfd_read function. This is
because if eventfd_write is not correctly working (return value is -1),
then monitor pthread will not be exited. In addition, eventfd_read is used to
read dummy value, so psi monitor will be exited correctly regardless of eventfd_read.

It solves problems reported by Coverity with cid = 1704480 and cid = 1704688.

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

index 7cefb6a..b9a05ce 100644 (file)
@@ -94,9 +94,6 @@ static void *psi_cpu_monitor_handler(struct psi_cpu_monitor_info *info)
 
 static void *psi_monitor_thread_destroy_handler(int *efd)
 {
-       eventfd_t dummy = 0;
-       eventfd_read(*efd, &dummy);
-
        pthread_exit(NULL);
 }
 
@@ -272,7 +269,17 @@ static int create_psi_monitor_thread(void)
 
 static void destroy_psi_monitor_thread(void)
 {
-       eventfd_write(g_psi_monitor_thread_destroy_event_fd, 1);
+       int ret;
+
+       if (g_psi_monitor_thread_destroy_event_fd < 0)
+               return;
+
+       ret = eventfd_write(g_psi_monitor_thread_destroy_event_fd, 1);
+       if (ret < 0) {
+               _E("Failed to destroy PSI monitor thread");
+               return;
+       }
+
        pthread_join(g_psi_monitor_thread, NULL);
 
        epoll_ctl(g_psi_monitor_epoll_fd, EPOLL_CTL_DEL,