Get ownership of acquire_fence fd when fd is set to tdm 35/314235/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 9 Jul 2024 06:04:36 +0000 (15:04 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Tue, 9 Jul 2024 06:12:24 +0000 (15:12 +0900)
It is better to transfer ownership when fd is set in tdm for fd management.

Change-Id: I1388bbd62fb22277541761d1358cf6edaa80d0ac

src/hal-api-tdm.c

index e997846746cf02b859a0d7755b03bd5000550465..2f41a3dbc021d7c7eaa9ba5200b5ddb45d0cc8c0 100644 (file)
        hwc_funcs = g_hal_tdm_backend_data->hwc_funcs; \
        if (!hwc_funcs->__func__) return HAL_TDM_ERROR_NOT_IMPLEMENTED;
 
+#define HWC_FUNC_ENTRY_FD_CLOSE(__func__, fd) \
+       hal_tdm_hwc_funcs *hwc_funcs; \
+       if (!hwc) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_INVALID_PARAMETER; } \
+       if (!g_hal_tdm_backend_data) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NO_MODULE; } \
+       if (!g_hal_tdm_backend_data->hwc_funcs) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NOT_IMPLEMENTED; } \
+       hwc_funcs = g_hal_tdm_backend_data->hwc_funcs; \
+       if (!hwc_funcs->__func__) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NOT_IMPLEMENTED; }
+
 #define HWC_FUNC_ENTRY_NULL(__func__) \
        hal_tdm_hwc_funcs *hwc_funcs; \
        if (!hwc) { if (*error) *error = HAL_TDM_ERROR_NOT_IMPLEMENTED; return NULL; } \
        hwc_window_funcs = g_hal_tdm_backend_data->hwc_window_funcs; \
        if (!hwc_window_funcs->__func__) return HAL_TDM_ERROR_NOT_IMPLEMENTED;
 
+#define HWC_WINDOW_FUNC_ENTRY_FD_CLOSE(__func__, fd) \
+       hal_tdm_hwc_window_funcs *hwc_window_funcs; \
+       if (!hwc_window) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_INVALID_PARAMETER; } \
+       if (!g_hal_tdm_backend_data) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NO_MODULE; } \
+       if (!g_hal_tdm_backend_data->hwc_window_funcs) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NOT_IMPLEMENTED; } \
+       hwc_window_funcs = g_hal_tdm_backend_data->hwc_window_funcs; \
+       if (!hwc_window_funcs->__func__) { if (fd >= 0) close(fd); return HAL_TDM_ERROR_NOT_IMPLEMENTED; }
+
 #define HWC_WINDOW_FUNC_ENTRY_NULL(__func__) \
        hal_tdm_hwc_window_funcs *hwc_window_funcs; \
        if (!hwc_window) { if (*error) *error = HAL_TDM_ERROR_NOT_IMPLEMENTED; return NULL; } \
@@ -753,7 +769,7 @@ hal_tdm_hwc_set_client_target_buffer_info(hal_tdm_hwc *hwc, hal_tdm_hwc_window_i
 EXTERN hal_tdm_error
 hal_tdm_hwc_set_client_target_acquire_fence(hal_tdm_hwc *hwc, int acquire_fence)
 {
-       HWC_FUNC_ENTRY(hwc_set_client_target_acquire_fence);
+       HWC_FUNC_ENTRY_FD_CLOSE(hwc_set_client_target_acquire_fence, acquire_fence);
 
        return hwc_funcs->hwc_set_client_target_acquire_fence(hwc, acquire_fence);
 }
@@ -939,7 +955,7 @@ hal_tdm_hwc_window_set_cursor_image(hal_tdm_hwc_window *hwc_window, int width, i
 EXTERN hal_tdm_error
 hal_tdm_hwc_window_set_acquire_fence(hal_tdm_hwc_window *hwc_window, int acquire_fence)
 {
-       HWC_WINDOW_FUNC_ENTRY(hwc_window_set_acquire_fence);
+       HWC_WINDOW_FUNC_ENTRY_FD_CLOSE(hwc_window_set_acquire_fence, acquire_fence);
 
        return hwc_window_funcs->hwc_window_set_acquire_fence(hwc_window, acquire_fence);
 }