From b4dc382734143599e7e099e26f39161ec0d54c97 Mon Sep 17 00:00:00 2001 From: Danny Wood Date: Thu, 20 Feb 2020 19:44:56 +0000 Subject: [PATCH] libhwc: fix potential crash when checking on update_stat_thread status Change-Id: I9060a57628c916c0b1b7a96dedf2286be2bd8475 --- libhwc/ExynosHWC.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libhwc/ExynosHWC.cpp b/libhwc/ExynosHWC.cpp index 30e1a22..21d7397 100644 --- a/libhwc/ExynosHWC.cpp +++ b/libhwc/ExynosHWC.cpp @@ -734,10 +734,13 @@ int exynos5_blank(struct hwc_composer_device_1 *dev, int disp, int blank) #endif pdev->primaryDisplay->mBlanked = !!blank; - if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive - if (fb_blank == FB_BLANK_POWERDOWN) { - pdev->update_stat_thread_flag = false; - pthread_join(pdev->update_stat_thread, 0); + /* Check if the thread is enabled before calling pthread_kill as we will seg fault otherwise */ + if(pdev->update_stat_thread_flag == true) { + if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive + if (fb_blank == FB_BLANK_POWERDOWN) { + pdev->update_stat_thread_flag = false; + pthread_join(pdev->update_stat_thread, 0); + } } } else { // thread is not alive if (fb_blank == FB_BLANK_UNBLANK && pdev->hwc_ctrl.dynamic_recomp_mode == true) @@ -1111,10 +1114,13 @@ int exynos_setPowerMode(struct hwc_composer_device_1* dev, int disp, int mode) #endif pdev->primaryDisplay->mBlanked = !!blank; - if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive - if (fb_blank == FB_BLANK_POWERDOWN) { - pdev->update_stat_thread_flag = false; - pthread_join(pdev->update_stat_thread, 0); + /* Check if the thread is enabled before calling pthread_kill as we will seg fault otherwise */ + if(pdev->update_stat_thread_flag == true) { + if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive + if (fb_blank == FB_BLANK_POWERDOWN) { + pdev->update_stat_thread_flag = false; + pthread_join(pdev->update_stat_thread, 0); + } } } else { // thread is not alive if (fb_blank == FB_BLANK_UNBLANK && pdev->hwc_ctrl.dynamic_recomp_mode == true) -- 2.20.1