int
init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd)
{
- tbm_bufmgr_sprd bufmgr_sprd;
tbm_bufmgr_backend bufmgr_backend;
+ tbm_bufmgr_sprd bufmgr_sprd;
+ int fp;
if (!bufmgr)
return 0;
}
if (tbm_backend_is_display_server()) {
- bufmgr_sprd->fd = -1;
-
bufmgr_sprd->fd = tbm_drm_helper_get_master_fd();
- if (bufmgr_sprd->fd < 0)
- bufmgr_sprd->fd = _tbm_sprd_open_drm();
-
if (bufmgr_sprd->fd < 0) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
- free(bufmgr_sprd);
- return 0;
+ bufmgr_sprd->fd = _tbm_sprd_open_drm();
+ if (bufmgr_sprd->fd < 0) {
+ TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to open drm!\n", getpid());
+ goto fail_open_drm;
+ }
}
tbm_drm_helper_set_tbm_master_fd(bufmgr_sprd->fd);
bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd);
-
if (!bufmgr_sprd->device_name) {
TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get device name!\n", getpid());
tbm_drm_helper_unset_tbm_master_fd();
- close(bufmgr_sprd->fd);
- free(bufmgr_sprd);
- return 0;
+ goto fail_get_device_name;
}
-
} else {
if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) {
TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid());
- free(bufmgr_sprd);
- return 0;
+ goto fail_get_auth_info;
}
}
bufmgr_sprd->hashBos = drmHashCreate();
//Check if the tbm manager supports dma fence or not.
- int fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY);
- int length;
- char buf[1];
+ fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY);
if (fp != -1) {
- length = read(fp, buf, 1);
+ char buf[1];
+ int length = read(fp, buf, 1);
if (length == 1 && buf[0] == '1')
bufmgr_sprd->use_dma_fence = 1;
}
if (!_bufmgr_init_cache_state(bufmgr_sprd)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: init bufmgr cache state failed!\n", getpid());
-
- if (tbm_backend_is_display_server())
- tbm_drm_helper_unset_tbm_master_fd();
-
- close(bufmgr_sprd->fd);
-
- free(bufmgr_sprd);
- return 0;
+ TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init bufmgr cache state\n", getpid());
+ goto fail_init_cache_state;
}
bufmgr_backend = tbm_backend_alloc();
if (!bufmgr_backend) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
-
- _bufmgr_deinit_cache_state(bufmgr_sprd);
-
- if (tbm_backend_is_display_server())
- tbm_drm_helper_unset_tbm_master_fd();
-
- close(bufmgr_sprd->fd);
-
- free(bufmgr_sprd);
- return 0;
+ TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to alloc backend!\n", getpid());
+ goto fail_alloc_backend;
}
bufmgr_backend->priv = (void *)bufmgr_sprd;
if (!tbm_backend_init(bufmgr, bufmgr_backend)) {
TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid());
- tbm_backend_free(bufmgr_backend);
-
- _bufmgr_deinit_cache_state(bufmgr_sprd);
-
- if (tbm_backend_is_display_server())
- tbm_drm_helper_unset_tbm_master_fd();
-
- close(bufmgr_sprd->fd);
-
- free(bufmgr_sprd);
- return 0;
+ goto fail_init_backend;
}
#ifdef DEBUG
{
char *env;
+
env = getenv("TBM_SPRD_DEBUG");
if (env) {
bDebug = atoi(env);
TBM_SPRD_LOG("TBM_SPRD_DEBUG=%s\n", env);
- } else {
+ } else
bDebug = 0;
- }
}
#endif
DBG("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(),
__FUNCTION__, bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!");
-
DBG("[libtbm-sprd:%d] %s fd:%d\n", getpid(),
__FUNCTION__, bufmgr_sprd->fd);
return 1;
-}
+fail_init_backend:
+ tbm_backend_free(bufmgr_backend);
+fail_alloc_backend:
+ _bufmgr_deinit_cache_state(bufmgr_sprd);
+fail_init_cache_state:
+ if (bufmgr_sprd->hashBos)
+ drmHashDestroy(bufmgr_sprd->hashBos);
+ if (tbm_backend_is_display_server())
+ tbm_drm_helper_unset_tbm_master_fd();
+fail_get_device_name:
+ close(bufmgr_sprd->fd);
+fail_get_auth_info:
+fail_open_drm:
+ free(bufmgr_sprd);
+ return 0;
+}