tbm_bufmgr_sprd: clean up init_tbm_bufmgr_priv() 32/94732/3
authorYoungJun Cho <yj44.cho@samsung.com>
Tue, 1 Nov 2016 02:41:16 +0000 (11:41 +0900)
committerYoungJun Cho <yj44.cho@samsung.com>
Mon, 7 Nov 2016 02:07:52 +0000 (11:07 +0900)
This patch cleans up code and
adds missed drmHashDestroy() calls.

Change-Id: Ib87679562358dedaceda09088b78f1f57926627f
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tbm_bufmgr_sprd.c

index 767f6e7..43c2fe3 100644 (file)
@@ -1904,8 +1904,9 @@ TBMModuleData tbmModuleData = { &SprdVersRec, init_tbm_bufmgr_priv};
 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;
@@ -1917,35 +1918,27 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd)
        }
 
        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;
                }
        }
 
@@ -1953,11 +1946,10 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd)
        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;
@@ -1966,30 +1958,14 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd)
        }
 
        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;
@@ -2013,39 +1989,43 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd)
 
        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;
+}