summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangyeon Lee <cyeon.lee@samsung.com>2024-07-23 19:58:01 +0900
committerChangyeon Lee <cyeon.lee@samsung.com>2024-07-24 15:09:56 +0900
commit686a602063251e9a9c8ca0087b94e2a8117b9f80 (patch)
tree16e702c6f3ab0732bd26419e8a8a8c559d2f8276
parent967955b993128372eff9112371c11ff7f2f7821b (diff)
downloadlibtbm-dumb-686a602063251e9a9c8ca0087b94e2a8117b9f80.tar.gz
libtbm-dumb-686a602063251e9a9c8ca0087b94e2a8117b9f80.tar.bz2
libtbm-dumb-686a602063251e9a9c8ca0087b94e2a8117b9f80.zip
Do not allocate backend data
backend data is allocated in hal-api Change-Id: I9ac07ed7d6451273e31a5f1ffef0dab6635bc37a
-rw-r--r--src/tbm_backend_dumb.c89
1 files changed, 28 insertions, 61 deletions
diff --git a/src/tbm_backend_dumb.c b/src/tbm_backend_dumb.c
index ac046cc..8e71b5b 100644
--- a/src/tbm_backend_dumb.c
+++ b/src/tbm_backend_dumb.c
@@ -1270,11 +1270,6 @@ hal_backend_tbm_dumb_exit(void *data)
bufmgr_data = (tbm_dumb_bufmgr *)backend_data->bufmgr;
TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, -1);
- if (backend_data->bufmgr_funcs)
- free(backend_data->bufmgr_funcs);
- if (backend_data->bo_funcs)
- free(backend_data->bo_funcs);
-
if (bufmgr_data->hashBos) {
while (drmHashFirst(bufmgr_data->hashBos, &key, &value) > 0) {
free(value);
@@ -1288,7 +1283,7 @@ hal_backend_tbm_dumb_exit(void *data)
close(bufmgr_data->fd);
free(backend_data->bufmgr);
- free(backend_data);
+ backend_data->bufmgr = NULL;
return HAL_TBM_ERROR_NONE;
}
@@ -1297,27 +1292,27 @@ static int
hal_backend_tbm_dumb_init(void **data)
{
hal_tbm_backend_data *backend_data = NULL;
- hal_tbm_bufmgr_funcs *bufmgr_funcs = NULL;
- hal_tbm_bo_funcs *bo_funcs = NULL;
tbm_dumb_bufmgr *bufmgr_data = NULL;
int drm_fd = -1;
uint64_t cap = 0;
uint32_t ret;
- /* allocate a hal_tbm_backend_data */
- backend_data = calloc(1, sizeof(struct _hal_tbm_backend_data));
+ if (!data) {
+ TBM_BACKEND_ERR("data is NULL");
+ return -1;
+ }
+
+ backend_data = *(hal_tbm_backend_data **)data;
if (!backend_data) {
- TBM_BACKEND_ERR("fail to alloc backend_data!");
- *data = NULL;
+ TBM_BACKEND_ERR("backend_data is NULL");
return -1;
}
- *data = backend_data;
/* allocate a hal_tbm_bufmgr */
bufmgr_data = calloc(1, sizeof(struct _tbm_dumb_bufmgr));
if (!bufmgr_data) {
TBM_BACKEND_ERR("fail to alloc bufmgr_data!");
- goto fail_alloc_bufmgr_data;
+ return -1;
}
backend_data->bufmgr = (hal_tbm_bufmgr *)bufmgr_data;
@@ -1360,61 +1355,33 @@ hal_backend_tbm_dumb_init(void **data)
/*Create Hash Table*/
bufmgr_data->hashBos = drmHashCreate();
- /* alloc and register bufmgr_funcs */
- bufmgr_funcs = calloc(1, sizeof(struct _hal_tbm_bufmgr_funcs));
- if (!bufmgr_funcs) {
- TBM_BACKEND_ERR("fail to alloc bufmgr_funcs!");
- goto fail_alloc_bufmgr_funcs;
- }
- backend_data->bufmgr_funcs = bufmgr_funcs;
-
- bufmgr_funcs->bufmgr_get_capabilities = tbm_dumb_bufmgr_get_capabilities;
- bufmgr_funcs->bufmgr_get_supported_formats = tbm_dumb_bufmgr_get_supported_formats;
- bufmgr_funcs->bufmgr_get_plane_data = tbm_dumb_bufmgr_get_plane_data;
- bufmgr_funcs->bufmgr_alloc_bo = tbm_dumb_bufmgr_alloc_bo;
- bufmgr_funcs->bufmgr_alloc_bo_with_format = NULL;
- bufmgr_funcs->bufmgr_import_fd = tbm_dumb_bufmgr_import_fd;
- bufmgr_funcs->bufmgr_import_key = tbm_dumb_bufmgr_import_key;
-
- /* alloc and register bo_funcs */
- bo_funcs = calloc(1, sizeof(struct _hal_tbm_bo_funcs));
- if (!bo_funcs) {
- TBM_BACKEND_ERR("fail to alloc bo_funcs!");
- goto fail_alloc_bo_funcs;
- }
- backend_data->bo_funcs = bo_funcs;
-
- bo_funcs->bo_free = tbm_dumb_bo_free;
- bo_funcs->bo_get_size = tbm_dumb_bo_get_size;
- bo_funcs->bo_get_memory_types = tbm_dumb_bo_get_memory_type;
- bo_funcs->bo_get_handle = tbm_dumb_bo_get_handle;
- bo_funcs->bo_map = tbm_dumb_bo_map;
- bo_funcs->bo_unmap = tbm_dumb_bo_unmap;
- bo_funcs->bo_lock = NULL;
- bo_funcs->bo_unlock = NULL;
- bo_funcs->bo_export_fd = tbm_dumb_bo_export_fd;
- bo_funcs->bo_export_key = tbm_dumb_bo_export_key;
+ backend_data->bufmgr_funcs->bufmgr_get_capabilities = tbm_dumb_bufmgr_get_capabilities;
+ backend_data->bufmgr_funcs->bufmgr_get_supported_formats = tbm_dumb_bufmgr_get_supported_formats;
+ backend_data->bufmgr_funcs->bufmgr_get_plane_data = tbm_dumb_bufmgr_get_plane_data;
+ backend_data->bufmgr_funcs->bufmgr_alloc_bo = tbm_dumb_bufmgr_alloc_bo;
+ backend_data->bufmgr_funcs->bufmgr_alloc_bo_with_format = NULL;
+ backend_data->bufmgr_funcs->bufmgr_import_fd = tbm_dumb_bufmgr_import_fd;
+ backend_data->bufmgr_funcs->bufmgr_import_key = tbm_dumb_bufmgr_import_key;
+
+ backend_data->bo_funcs->bo_free = tbm_dumb_bo_free;
+ backend_data->bo_funcs->bo_get_size = tbm_dumb_bo_get_size;
+ backend_data->bo_funcs->bo_get_memory_types = tbm_dumb_bo_get_memory_type;
+ backend_data->bo_funcs->bo_get_handle = tbm_dumb_bo_get_handle;
+ backend_data->bo_funcs->bo_map = tbm_dumb_bo_map;
+ backend_data->bo_funcs->bo_unmap = tbm_dumb_bo_unmap;
+ backend_data->bo_funcs->bo_lock = NULL;
+ backend_data->bo_funcs->bo_unlock = NULL;
+ backend_data->bo_funcs->bo_export_fd = tbm_dumb_bo_export_fd;
+ backend_data->bo_funcs->bo_export_key = tbm_dumb_bo_export_key;
TBM_BACKEND_DBG("drm_fd:%d", bufmgr_data->fd);
return HAL_TBM_ERROR_NONE;
-fail_alloc_bo_funcs:
- free(bufmgr_funcs);
-fail_alloc_bufmgr_funcs:
- if (bufmgr_data->hashBos)
- drmHashDestroy(bufmgr_data->hashBos);
fail_get_cap:
- if (backend_data->drm_info.is_master)
- close(bufmgr_data->fd);
- else
- close(drm_fd);
+ close(drm_fd);
fail_open_drm:
free(bufmgr_data);
-fail_alloc_bufmgr_data:
- free(backend_data);
-
- *data = NULL;
return -1;
}