From: Youngjae Cho Date: Tue, 18 Feb 2025 06:59:56 +0000 (+0900) Subject: common: Fix __open/close_backend() to control usage_count exclusively X-Git-Tag: accepted/tizen/unified/20250310.131219^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F319811%2F6;p=platform%2Fhal%2Fapi%2Fcommon.git common: Fix __open/close_backend() to control usage_count exclusively Let the usage_count be encapsulated within the __open_backend() and __close_backend(). On calling those functions, the usage_count will be calculated, and operations will be or won't be taken based on the usage_count. Nothing will be necessary to manage the usage_count outside of __open_backend() or __close_backend(). Change-Id: If4c3253be8e830f727b8b7741a3b946a1bc6e3fa Signed-off-by: Youngjae Cho --- diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 8773a81..dc4a102 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -162,8 +162,8 @@ static int __open_backend(struct __hal_module_info *info) const char *backend_library_name = NULL; int ret; - if (info->backend && info->handle) - return 0; + if (info->usage_count > 0) + goto out; backend_library_name = get_backend_library_name(info); if (!backend_library_name) { @@ -201,6 +201,9 @@ static int __open_backend(struct __hal_module_info *info) goto err_dlclose; } +out: + info->usage_count++; + return 0; err_dlclose: @@ -214,12 +217,15 @@ err: static void __close_backend(struct __hal_module_info *info) { - if (!info->backend || !info->handle) + info->usage_count--; + + if (info->usage_count > 0) return; if (info->handle) dlclose(info->handle); + info->usage_count = 0; info->backend = NULL; info->handle = NULL; } @@ -373,8 +379,6 @@ static int __get_backend(enum hal_module module, goto err_dlclose; } - info->usage_count++; - _I("%s: Get HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, info->backend->name, info->backend->vendor, get_backend_library_name(info), info->usage_count, @@ -439,20 +443,18 @@ static int __put_backend(enum hal_module module, goto out; } - info->usage_count--; - _I("%s: Exit and Prepare to put HAL backend: name(%s)/vendor(%s)/library(%s)/count(%d) by %s\n", info->module_name, info->backend->name, info->backend->vendor, get_backend_library_name(info), info->usage_count, program_invocation_name); + __close_backend(info); + if (info->usage_count > 0) { ret = 0; goto out; } - __close_backend(info); - _I("%s: Put HAL backend: library(%s)/count(%d) by %s\n", info->module_name, get_backend_library_name(info), info->usage_count, program_invocation_name); @@ -504,7 +506,7 @@ static int __get_backend_data(enum hal_module module, if (!info->backend->name || (len + 1 > name_size)) { _E("%s: Invalid size of name[] array\n", info->module_name); ret = -EINVAL; - goto err_conf_exit; + goto err_close_backend; } strncpy(name, info->backend->name, name_size); @@ -516,7 +518,7 @@ static int __get_backend_data(enum hal_module module, if (!info->backend->vendor || (len + 1 > vendor_size)) { _E("%s: Invalid size of vendor[] array\n", info->module_name); ret = -EINVAL; - goto err_conf_exit; + goto err_close_backend; } strncpy(vendor, info->backend->vendor, vendor_size); @@ -526,10 +528,12 @@ static int __get_backend_data(enum hal_module module, } else { _E("%s: Failed to get backend data\n", info->module_name); ret = -EINVAL; - goto err_conf_exit; + goto err_close_backend; } ret = 0; +err_close_backend: + __close_backend(info); err_conf_exit: _hal_api_conf_exit(); err_unlock: