lowmem-monitor: Check return value of eventfd_write and remove useless code 73/297673/3 accepted/tizen/unified/20230825.044230 accepted/tizen/unified/riscv/20230829.072052
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 22 Aug 2023 11:47:50 +0000 (20:47 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 23 Aug 2023 02:03:09 +0000 (11:03 +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: Ic753aaf3b96c95d7f1e2e629c165800728b92289
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-limiter/memory/lowmem-monitor-psi.c

index 696036a..f498f4a 100644 (file)
@@ -95,9 +95,6 @@ static void *psi_memory_monitor_handler(struct psi_memory_monitor_info *info)
 
 static void *psi_monitor_thread_destroy_handler(int *efd)
 {
-       eventfd_t dummy = 0;
-       eventfd_read(*efd, &dummy);
-
        pthread_exit(NULL);
 }
 
@@ -280,7 +277,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");
+               assert(0);
+       }
+
        pthread_join(g_psi_monitor_thread, NULL);
 
        epoll_ctl(g_psi_monitor_epoll_fd, EPOLL_CTL_DEL, g_psi_monitor_thread_destroy_event_fd, NULL);