From: Yunhee Seo Date: Mon, 15 Apr 2024 07:59:05 +0000 (+0900) Subject: hal-api-device: Remove unnecessary hal_initialized flag X-Git-Tag: accepted/tizen/unified/20240614.084933~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1926ea7c54dc176921c19c51414c8e82d10d568d;p=platform%2Fhal%2Fapi%2Fdevice.git hal-api-device: Remove unnecessary hal_initialized flag Before using hal api function, loading hal backend is essential. Thus, before calling hal backend function, hal backend loading is always checked. However hal_initialized flag is being used uncessarily in duplicate. To avoid duplcated operation, hal_initialized flag is removed. Change-Id: I64ff8e3f7405d12c8fe82038f96c96f21748cf8f Signed-off-by: Yunhee Seo --- diff --git a/include/common.h b/include/common.h index 95c3b5d..b5811bf 100644 --- a/include/common.h +++ b/include/common.h @@ -31,10 +31,6 @@ #define _E(x, ...) #endif -#define HAL_INITIALIZED_FAILED -1 -#define HAL_INITIALIZED_NOT 0 -#define HAL_INITIALIZED_SUCCEEDED 1 - #ifndef __CONSTRUCTOR__ #define __CONSTRUCTOR__ __attribute__ ((constructor)) #endif diff --git a/src/battery.c b/src/battery.c index 01bad7d..aa28062 100644 --- a/src/battery.c +++ b/src/battery.c @@ -20,12 +20,6 @@ #include "common.h" static hal_backend_battery_funcs *hal_battery_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_battery_get_backend(void) { @@ -37,11 +31,9 @@ int hal_device_battery_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_BATTERY, (void **)&hal_battery_funcs); if (ret < 0) { _E("Failed to get battery backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -52,7 +44,6 @@ int hal_device_battery_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_BATTERY, (void *)hal_battery_funcs); hal_battery_funcs = NULL; - hal_initialized = 0; return 0; } @@ -61,7 +52,7 @@ int hal_device_battery_register_changed_event(BatteryUpdated updated_cb, void *d { int ret; - if (!hal_battery_funcs && !hal_initialized) { + if (!hal_battery_funcs) { if ((ret = hal_device_battery_get_backend()) < 0) return ret; } @@ -77,7 +68,7 @@ int hal_device_battery_unregister_changed_event(BatteryUpdated updated_cb) { int ret; - if (!hal_battery_funcs && !hal_initialized) { + if (!hal_battery_funcs) { if ((ret = hal_device_battery_get_backend()) < 0) return ret; } @@ -94,7 +85,7 @@ int hal_device_battery_get_current_state(BatteryUpdated updated_cb, void *data) { int ret; - if (!hal_battery_funcs && !hal_initialized) { + if (!hal_battery_funcs) { if ((ret = hal_device_battery_get_backend()) < 0) return ret; } diff --git a/src/bezel.c b/src/bezel.c index f650b8d..7683545 100644 --- a/src/bezel.c +++ b/src/bezel.c @@ -21,12 +21,6 @@ #include "common.h" static hal_backend_bezel_funcs *hal_bezel_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_bezel_get_backend(void) { @@ -38,11 +32,9 @@ int hal_device_bezel_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_BEZEL, (void **)&hal_bezel_funcs); if (ret < 0) { _E("Failed to get bezel backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -53,7 +45,6 @@ int hal_device_bezel_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_BEZEL, (void *)hal_bezel_funcs); hal_bezel_funcs = NULL; - hal_initialized = 0; return 0; } @@ -62,7 +53,7 @@ int hal_device_bezel_get_state(enum bezel_state *state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } @@ -78,7 +69,7 @@ int hal_device_bezel_set_state(enum bezel_state state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } @@ -94,7 +85,7 @@ int hal_device_bezel_get_sw_state(enum bezel_state *state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } @@ -110,7 +101,7 @@ int hal_device_bezel_set_sw_state(enum bezel_state state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } @@ -126,7 +117,7 @@ int hal_device_bezel_get_vib_state(enum bezel_vib_state *state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } @@ -142,7 +133,7 @@ int hal_device_bezel_set_vib_state(enum bezel_vib_state state) { int ret; - if (!hal_bezel_funcs && !hal_initialized) { + if (!hal_bezel_funcs) { if ((ret = hal_device_bezel_get_backend()) < 0) return ret; } diff --git a/src/external_connection.c b/src/external_connection.c index 7ecc2d8..c14a54c 100644 --- a/src/external_connection.c +++ b/src/external_connection.c @@ -21,12 +21,6 @@ #include "common.h" static hal_backend_external_connection_funcs *hal_external_connection_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_external_connection_get_backend(void) { @@ -38,11 +32,9 @@ int hal_device_external_connection_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, (void **)&hal_external_connection_funcs); if (ret < 0) { _E("Failed to get external connection backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -53,7 +45,6 @@ int hal_device_external_connection_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, (void *)hal_external_connection_funcs); hal_external_connection_funcs = NULL; - hal_initialized = 0; return 0; } @@ -63,7 +54,7 @@ int hal_device_external_connection_register_changed_event(ConnectionUpdated upda { int ret; - if (!hal_external_connection_funcs && !hal_initialized) { + if (!hal_external_connection_funcs) { if ((ret = hal_device_external_connection_get_backend()) < 0) return ret; } @@ -79,7 +70,7 @@ int hal_device_external_connection_unregister_changed_event(ConnectionUpdated up { int ret; - if (!hal_external_connection_funcs && !hal_initialized) { + if (!hal_external_connection_funcs) { if ((ret = hal_device_external_connection_get_backend()) < 0) return ret; } @@ -96,7 +87,7 @@ int hal_device_external_connection_get_current_state(ConnectionUpdated updated_c { int ret; - if (!hal_external_connection_funcs && !hal_initialized) { + if (!hal_external_connection_funcs) { if ((ret = hal_device_external_connection_get_backend()) < 0) return ret; } diff --git a/src/hal-api-device-haptic.c b/src/hal-api-device-haptic.c index ba7b7b3..fc4bead 100644 --- a/src/hal-api-device-haptic.c +++ b/src/hal-api-device-haptic.c @@ -80,7 +80,7 @@ int hal_device_haptic_get_device_count(int *count) { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } @@ -98,7 +98,7 @@ int hal_device_haptic_open_device(int *handle) { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } @@ -116,7 +116,7 @@ int hal_device_haptic_close_device(int handle) { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } @@ -131,7 +131,7 @@ bool hal_device_haptic_is_valid(void) { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } @@ -146,7 +146,7 @@ int hal_device_haptic_vibrate(int handle, int duration, int frequency, int overd { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } @@ -162,7 +162,7 @@ int hal_device_haptic_stop_device(int handle) { int ret; - if (!hal_device_haptic_funcs && !hal_initialized) { + if (!hal_device_haptic_funcs) { if ((ret = hal_device_haptic_get_backend()) < 0) return ret; } diff --git a/src/input.c b/src/input.c index 2777fcd..1f2ae1b 100644 --- a/src/input.c +++ b/src/input.c @@ -20,7 +20,6 @@ #include "common.h" static hal_backend_device_input_funcs *hal_device_input_funcs = NULL; -static int hal_initialized = HAL_INITIALIZED_NOT; int hal_device_input_get_backend(void) { @@ -32,11 +31,9 @@ int hal_device_input_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_INPUT, (void **)&hal_device_input_funcs); if (ret < 0) { _E("Failed to get input backend"); - hal_initialized = HAL_INITIALIZED_FAILED; return ret; } - hal_initialized = HAL_INITIALIZED_SUCCEEDED; return 0; } @@ -54,7 +51,6 @@ int hal_device_input_put_backend(void) } hal_device_input_funcs = NULL; - hal_initialized = HAL_INITIALIZED_NOT; return 0; } @@ -63,7 +59,7 @@ int hal_device_input_set_event_state(int input_device_id, int on) { int ret; - if (!hal_device_input_funcs && !hal_initialized) { + if (!hal_device_input_funcs) { if ((ret = hal_device_input_get_backend()) < 0) return ret; } @@ -79,7 +75,7 @@ int hal_device_input_get_event_state(int input_device_id, int* on) { int ret; - if (!hal_device_input_funcs && !hal_initialized) { + if (!hal_device_input_funcs) { if ((ret = hal_device_input_get_backend()) < 0) return ret; } diff --git a/src/ir.c b/src/ir.c index 3d64039..687e59a 100644 --- a/src/ir.c +++ b/src/ir.c @@ -21,12 +21,6 @@ #include "common.h" static hal_backend_ir_funcs *hal_ir_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_ir_get_backend(void) { @@ -38,11 +32,9 @@ int hal_device_ir_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_IR, (void **)&hal_ir_funcs); if (ret < 0) { _E("Failed to get ir backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -53,7 +45,6 @@ int hal_device_ir_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_IR, (void *)hal_ir_funcs); hal_ir_funcs = NULL; - hal_initialized = 0; return 0; } @@ -63,7 +54,7 @@ int hal_device_ir_is_available(bool *available) { int ret; - if (!hal_ir_funcs && !hal_initialized) { + if (!hal_ir_funcs) { if ((ret = hal_device_ir_get_backend()) < 0) return ret; } @@ -79,7 +70,7 @@ int hal_device_ir_transmit(int *frequency_pattern, int size) { int ret; - if (!hal_ir_funcs && !hal_initialized) { + if (!hal_ir_funcs) { if ((ret = hal_device_ir_get_backend()) < 0) return ret; } diff --git a/src/led.c b/src/led.c index 7f04937..b856c93 100644 --- a/src/led.c +++ b/src/led.c @@ -20,12 +20,6 @@ #include "hal-led-interface.h" static hal_backend_led_funcs *hal_led_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_led_get_backend(void) { @@ -37,11 +31,9 @@ int hal_device_led_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_LED, (void **)&hal_led_funcs); if (ret < 0) { _E("Failed to get led backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -52,7 +44,6 @@ int hal_device_led_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_LED, (void *)hal_led_funcs); hal_led_funcs = NULL; - hal_initialized = 0; return 0; } @@ -61,7 +52,7 @@ int hal_device_led_set_state(enum led_device_type type, struct led_state *state) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -105,7 +96,7 @@ int hal_device_led_get_state(enum led_device_type type, struct led_state **state { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -149,7 +140,7 @@ int hal_device_led_get_number(void) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -166,7 +157,7 @@ int hal_device_led_set_number(int number) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -185,7 +176,7 @@ int hal_device_led_get_max_num(void) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -202,7 +193,7 @@ int hal_device_keyled_set_state(struct keyled_state *state) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } @@ -219,7 +210,7 @@ int hal_device_keyled_get_state(int *keycode, int *brightness) { int ret; - if (!hal_led_funcs && !hal_initialized) { + if (!hal_led_funcs) { if ((ret = hal_device_led_get_backend()) < 0) return ret; } diff --git a/src/memory.c b/src/memory.c index 9acd608..774bc32 100644 --- a/src/memory.c +++ b/src/memory.c @@ -61,7 +61,7 @@ int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info) { int ret; - if (!hal_memory_funcs && !hal_initialized) { + if (!hal_memory_funcs) { if ((ret = hal_device_memory_get_backend()) < 0) return ret; } @@ -76,7 +76,7 @@ int hal_device_memory_get_gem_info(int pid, struct gem_info *info) { int ret; - if (!hal_memory_funcs && !hal_initialized) { + if (!hal_memory_funcs) { if ((ret = hal_device_memory_get_backend()) < 0) return ret; } diff --git a/src/power.c b/src/power.c index cb03720..997db61 100644 --- a/src/power.c +++ b/src/power.c @@ -20,7 +20,6 @@ #include "common.h" static hal_backend_device_power_funcs *hal_device_power_funcs = NULL; -static int hal_initialized = HAL_INITIALIZED_NOT; int hal_device_power_get_backend(void) { @@ -31,11 +30,9 @@ int hal_device_power_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_POWER, (void **)&hal_device_power_funcs); if (ret < 0) { _E("Failed to get device power backend"); - hal_initialized = HAL_INITIALIZED_FAILED; return ret; } - hal_initialized = HAL_INITIALIZED_SUCCEEDED; return 0; } @@ -52,7 +49,6 @@ int hal_device_power_put_backend(void) } hal_device_power_funcs = NULL; - hal_initialized = HAL_INITIALIZED_NOT; return 0; } @@ -61,7 +57,7 @@ int hal_device_power_get_wakeup_reason(enum hal_device_power_transition_reason * { int ret; - if (!hal_device_power_funcs && !hal_initialized) { + if (!hal_device_power_funcs) { if ((ret = hal_device_power_get_backend()) < 0) return ret; } diff --git a/src/thermal.c b/src/thermal.c index 6e056e4..2958df0 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -20,12 +20,6 @@ #include "hal-thermal-interface.h" static hal_backend_thermal_funcs *hal_thermal_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_thermal_get_backend(void) { @@ -37,11 +31,9 @@ int hal_device_thermal_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_THERMAL, (void **)&hal_thermal_funcs); if (ret < 0) { _E("Failed to get thermal backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -52,7 +44,6 @@ int hal_device_thermal_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_THERMAL, (void *)hal_thermal_funcs); hal_thermal_funcs = NULL; - hal_initialized = 0; return 0; } @@ -61,7 +52,7 @@ int hal_device_thermal_get_info(hal_device_thermal_e type, struct thermal_info * { int ret; - if (!hal_thermal_funcs && !hal_initialized) { + if (!hal_thermal_funcs) { if ((ret = hal_device_thermal_get_backend()) < 0) return ret; } @@ -77,7 +68,7 @@ int hal_device_thermal_register_changed_event(ThermalUpdated updated_cb, void *d { int ret; - if (!hal_thermal_funcs && !hal_initialized) { + if (!hal_thermal_funcs) { if ((ret = hal_device_thermal_get_backend()) < 0) return ret; } @@ -93,7 +84,7 @@ int hal_device_thermal_unregister_changed_event(ThermalUpdated updated_cb) { int ret; - if (!hal_thermal_funcs && !hal_initialized) { + if (!hal_thermal_funcs) { if ((ret = hal_device_thermal_get_backend()) < 0) return ret; } diff --git a/src/touchscreen.c b/src/touchscreen.c index d4e0560..b920b71 100644 --- a/src/touchscreen.c +++ b/src/touchscreen.c @@ -22,12 +22,6 @@ #include "common.h" static hal_backend_touchscreen_funcs *hal_touchscreen_funcs = NULL; -/* --1 : failed to initialize -0 : not initialized -1 : succeeded to initialize -*/ -static int hal_initialized = 0; int hal_device_touchscreen_get_backend(void) { @@ -39,11 +33,9 @@ int hal_device_touchscreen_get_backend(void) ret = hal_common_get_backend(HAL_MODULE_DEVICE_TOUCHSCREEN, (void **)&hal_touchscreen_funcs); if (ret < 0) { _E("Failed to get touchscreen backend"); - hal_initialized = -1; return -EINVAL; } - hal_initialized = 1; return 0; } @@ -54,7 +46,6 @@ int hal_device_touchscreen_put_backend(void) hal_common_put_backend(HAL_MODULE_DEVICE_TOUCHSCREEN, (void *)hal_touchscreen_funcs); hal_touchscreen_funcs = NULL; - hal_initialized = 0; return 0; } @@ -64,7 +55,7 @@ int hal_device_touchscreen_get_state(enum touchscreen_state *state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; } @@ -80,7 +71,7 @@ int hal_device_touchscreen_set_state(enum touchscreen_state state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; } @@ -96,7 +87,7 @@ int hal_device_touchscreen_get_powersaving(int *state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; } @@ -112,7 +103,7 @@ int hal_device_touchscreen_set_powersaving(int state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; } @@ -128,7 +119,7 @@ int hal_device_touchscreen_glove_mode_get_state(int *state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; } @@ -144,7 +135,7 @@ int hal_device_touchscreen_glove_mode_set_state(int state) { int ret; - if (!hal_touchscreen_funcs && !hal_initialized) { + if (!hal_touchscreen_funcs) { if ((ret = hal_device_touchscreen_get_backend()) < 0) return ret; }