From bd36cff694a73cbb561179d64461c7cb49a1ac84 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Thu, 10 Nov 2016 20:04:35 +0900 Subject: [PATCH] tbm_bufmgr: clean up load module codes This patch cleans up load module codes. - Tries not to use over 2-depth condition. Change-Id: I0bcd7e0308e85028db4bf7b2c740cf052b1ec245 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr.c | 117 ++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 62 deletions(-) diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 80be27a..a70fb55 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -477,102 +477,95 @@ _check_version(TBMModuleVersionInfo *data) static int _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file) { - char path[PATH_MAX] = { 0, }; - TBMModuleData *initdata = NULL; + char path[PATH_MAX] = {0, }; + TBMModuleVersionInfo *vers; + TBMModuleData *initdata; + ModuleInitProc init; void *module_data; snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file); module_data = dlopen(path, RTLD_LAZY); if (!module_data) { - TBM_LOG_E("failed to load module: %s(%s)\n", - dlerror(), file); + TBM_LOG_E("failed to load module: %s(%s)\n", dlerror(), file); return 0; } initdata = dlsym(module_data, "tbmModuleData"); - if (initdata) { - ModuleInitProc init; - TBMModuleVersionInfo *vers; + if (!initdata) { + TBM_LOG_E("Error: module does not have data object.\n"); + goto err; + } - vers = initdata->vers; - init = initdata->init; + vers = initdata->vers; + if (!vers) { + TBM_LOG_E("Error: module does not supply version information.\n"); + goto err; + } - if (vers) { - if (!_check_version(vers)) { - dlclose(module_data); - return 0; - } - } else { - TBM_LOG_E("Error: module does not supply version information.\n"); + init = initdata->init; + if (!init) { + TBM_LOG_E("Error: module does not supply init symbol.\n"); + goto err; + } - dlclose(module_data); - return 0; - } + if (!_check_version(vers)) { + TBM_LOG_E("Fail to check version.\n"); + goto err; + } - if (init) { - if (!init(bufmgr, fd)) { - TBM_LOG_E("Fail to init module(%s)\n", - file); - dlclose(module_data); - return 0; - } + if (!init(bufmgr, fd)) { + TBM_LOG_E("Fail to init module(%s)\n", file); + goto err; + } - if (!bufmgr->backend || !bufmgr->backend->priv) { - TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", - file); - dlclose(module_data); - return 0; - } - } else { - TBM_LOG_E("Error: module does not supply init symbol.\n"); - dlclose(module_data); - return 0; - } - } else { - TBM_LOG_E("Error: module does not have data object.\n"); - dlclose(module_data); - return 0; + if (!bufmgr->backend || !bufmgr->backend->priv) { + TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file); + goto err; } bufmgr->module_data = module_data; - TBM_DBG("Success to load module(%s)\n", - file); + TBM_DBG("Success to load module(%s)\n", file); return 1; + +err: + dlclose(module_data); + return 0; } static int _tbm_load_module(tbm_bufmgr bufmgr, int fd) { struct dirent **namelist; - const char *p = NULL; - int n; - int ret = 0; + int ret = 0, n; /* load bufmgr priv from default lib */ - ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB); + if (_tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB)) + return 1; /* load bufmgr priv from configured path */ - if (!ret) { - n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort); - if (n < 0) { - TBM_LOG_E("no files : %s\n", - BUFMGR_MODULE_DIR); - } else { - while (n--) { - if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) { - p = strstr(namelist[n]->d_name, SUFFIX_LIB); - if (p && !strcmp(p, SUFFIX_LIB)) - ret = _tbm_bufmgr_load_module(bufmgr, fd, namelist[n]->d_name); - } - free(namelist[n]); - } - free(namelist); + n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort); + if (n < 0) { + TBM_LOG_E("no files : %s\n", BUFMGR_MODULE_DIR); + return 0; + } + + while (n--) { + if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) { + const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB); + + if (p && !strcmp(p, SUFFIX_LIB)) + ret = _tbm_bufmgr_load_module(bufmgr, fd, + namelist[n]->d_name); } + + free(namelist[n]); } + free(namelist); + return ret; } /* LCOV_EXCL_STOP */ -- 2.34.1