diff options
author | Gilbok Lee <gilbok.lee@samsung.com> | 2024-01-16 15:37:13 +0900 |
---|---|---|
committer | Gilbok Lee <gilbok.lee@samsung.com> | 2024-01-22 11:52:52 +0900 |
commit | a672edbba43f24d0ff70dc83f2413fde6a478dd4 (patch) | |
tree | 33e583e32c532bba85eb588b4a9190320fdcf25c /src/mm_radio_priv_hal.c | |
parent | 1d1f94b1bcc4a2c371e3ab8744fbb134362efb84 (diff) | |
download | libmm-radio-tizen.tar.gz libmm-radio-tizen.tar.bz2 libmm-radio-tizen.zip |
Fix coverity/Svace issues (BAD_CHECK_OF_WAIT_COND, MISSING_UNLOCK, NULL_AFTER_DEREF)HEADaccepted/tizen/unified/x/20240205.063846accepted/tizen/unified/toolchain/20240311.065435accepted/tizen/unified/20240131.175405tizenaccepted/tizen_unified_xaccepted/tizen_unified_toolchainaccepted/tizen_unified
- Remove unused volume mutex
- Add check wait condition
- Remove unnecessary code
[Version] 0.2.51
[Issue Type] Coverity
Change-Id: I9e4cd3ae97183c297cf5a963597f14cfeb6a4adc
Diffstat (limited to 'src/mm_radio_priv_hal.c')
-rw-r--r-- | src/mm_radio_priv_hal.c | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/src/mm_radio_priv_hal.c b/src/mm_radio_priv_hal.c index c65f50e..c83627f 100644 --- a/src/mm_radio_priv_hal.c +++ b/src/mm_radio_priv_hal.c @@ -719,10 +719,13 @@ int _mmradio_seek(mm_radio_t *radio, MMRadioSeekDirectionType direction) p_thread = &radio->thread[MM_RADIO_THREAD_SEEK]; MMRADIO_CHECK_ARG(p_thread); + MMRADIO_THREAD_LOCK(p_thread); if (p_thread->is_running) { MMRADIO_LOG_ERROR("[RADIO_ERROR_INVALID_OPERATION]radio is seeking, can't serve another request try again"); + MMRADIO_THREAD_UNLOCK(p_thread); return MM_ERROR_RADIO_INTERNAL; } + MMRADIO_THREAD_UNLOCK(p_thread); radio->seek_unmute = false; @@ -776,6 +779,14 @@ int _mmradio_start_scan(mm_radio_t *radio) p_thread = &radio->thread[MM_RADIO_THREAD_SCAN]; MMRADIO_CHECK_ARG(p_thread); + MMRADIO_THREAD_LOCK(p_thread); + if (p_thread->is_running) { + MMRADIO_LOG_ERROR("[MM_ERROR_RADIO_INVALID_STATE]radio is scanning, can't serve another request try again"); + MMRADIO_THREAD_UNLOCK(p_thread); + return MM_ERROR_RADIO_INVALID_STATE; + } + MMRADIO_THREAD_UNLOCK(p_thread); + p_thread->stop = false; ret = __mmradio_prepare_radio_device(radio); @@ -851,14 +862,12 @@ void __mmradio_scan_thread(mm_radio_t *radio) MMRADIO_CHECK_ARG_RETURN_VOID(p_thread); MMRADIO_THREAD_LOCK(p_thread); - MMRADIO_THREAD_SIGNAL(p_thread); - MMRADIO_THREAD_UNLOCK(p_thread); - - MMRADIO_THREAD_LOCK(p_thread); while (!p_thread->thread_exit) { - MMRADIO_LOG_DEBUG("scan thread started. waiting for signal."); - MMRADIO_THREAD_WAIT(p_thread); + while (!p_thread->is_running) { + MMRADIO_LOG_DEBUG("scan thread started. waiting for signal."); + MMRADIO_THREAD_WAIT(p_thread); + } if (p_thread->thread_exit) { MMRADIO_LOG_DEBUG("exiting scan thread"); @@ -1022,14 +1031,12 @@ void __mmradio_seek_thread(mm_radio_t *radio) MMRADIO_CHECK_ARG_RETURN_VOID(p_thread); MMRADIO_THREAD_LOCK(p_thread); - MMRADIO_THREAD_SIGNAL(p_thread); - MMRADIO_THREAD_UNLOCK(p_thread); - - MMRADIO_THREAD_LOCK(p_thread); while (!p_thread->thread_exit) { - MMRADIO_LOG_DEBUG("seek thread started. waiting for signal."); - MMRADIO_THREAD_WAIT(p_thread); + while (!p_thread->is_running) { + MMRADIO_LOG_DEBUG("seek thread started. waiting for signal."); + MMRADIO_THREAD_WAIT(p_thread); + } if (p_thread->thread_exit) { MMRADIO_LOG_DEBUG("exiting seek thread"); @@ -1387,15 +1394,12 @@ int _mmradio_set_volume(mm_radio_t *radio, float volume) MMRADIO_LOG_INFO("Setting %f volume", volume); - MMRADIO_VOLUME_LOCK(radio); radio->local_volume = volume; if (radio->vstream) sound_manager_set_virtual_stream_volume(radio->vstream, (double)radio->local_volume); - MMRADIO_VOLUME_UNLOCK(radio); - MMRADIO_LOG_FLEAVE(); return MM_ERROR_NONE; @@ -1412,9 +1416,7 @@ int _mmradio_get_volume(mm_radio_t *radio, float *pVolume) MMRADIO_RETURN_VAL_IF_FAIL(pVolume, MM_ERROR_INVALID_ARGUMENT); - MMRADIO_VOLUME_LOCK(radio); *pVolume = radio->local_volume; - MMRADIO_VOLUME_UNLOCK(radio); MMRADIO_LOG_FLEAVE(); @@ -1464,25 +1466,19 @@ static int __mmradio_create_thread_type(mm_radio_t *radio, MMRadioThreadTypes ty } p_thread = &radio->thread[type]; + p_thread->is_running = false; MMRADIO_CHECK_ARG(p_thread); MMRADIO_INIT_MUTEX(p_thread->mutex); MMRADIO_INIT_COND(p_thread->cond); - MMRADIO_THREAD_LOCK(p_thread); p_thread->thread_id = pthread_create(&p_thread->thread, NULL, (void *)__mmradio_thread_function[type], (void *)radio); if (p_thread->thread_id) { MMRADIO_LOG_DEBUG("failed to create thread : [%d]", type); - MMRADIO_THREAD_UNLOCK(p_thread); return MM_ERROR_RADIO_INTERNAL; } - MMRADIO_LOG_DEBUG("wait for [%d] thread", type); - MMRADIO_THREAD_WAIT(p_thread); - MMRADIO_LOG_DEBUG("[%d] thread started", type); - MMRADIO_THREAD_UNLOCK(p_thread); - return MM_ERROR_NONE; ERROR: @@ -1502,7 +1498,6 @@ static int __mmradio_create_threads(mm_radio_t *radio) MMRADIO_CHECK_INSTANCE(radio); MMRADIO_INIT_MUTEX(radio->cmd_lock); - MMRADIO_INIT_MUTEX(radio->volume_lock); MMRADIO_INIT_MUTEX(radio->hal_seek_mutex); for (type = (int)MM_RADIO_THREAD_MSG; type < (int)MM_RADIO_THREAD_NUM; type++) { @@ -1520,7 +1515,6 @@ static int __mmradio_create_threads(mm_radio_t *radio) ERROR: pthread_mutex_destroy(&radio->cmd_lock); - pthread_mutex_destroy(&radio->volume_lock); pthread_mutex_destroy(&radio->hal_seek_mutex); MMRADIO_LOG_FLEAVE(); @@ -1560,6 +1554,7 @@ static void __mmradio_destroy_thread_type(mm_radio_t *radio, MMRadioThreadTypes case MM_RADIO_THREAD_SCAN: MMRADIO_THREAD_LOCK(p_thread); p_thread->thread_exit = true; + p_thread->is_running = true; MMRADIO_THREAD_SIGNAL(p_thread); MMRADIO_THREAD_UNLOCK(p_thread); pthread_join(p_thread->thread, NULL); @@ -1589,7 +1584,6 @@ static void __mmradio_destroy_threads(mm_radio_t *radio) __mmradio_destroy_thread_type(radio, (MMRadioThreadTypes)type); pthread_mutex_destroy(&radio->cmd_lock); - pthread_mutex_destroy(&radio->volume_lock); pthread_mutex_destroy(&radio->hal_seek_mutex); MMRADIO_LOG_FLEAVE(); @@ -1625,11 +1619,6 @@ void __mmradio_msg_thread(mm_radio_t *radio) p_thread->thread_exit = false; - - MMRADIO_THREAD_LOCK(p_thread); - MMRADIO_THREAD_SIGNAL(p_thread); - MMRADIO_THREAD_UNLOCK(p_thread); - /* we run a while one loop*/ while (!p_thread->thread_exit) { msg = (mm_radio_msg_t *)g_async_queue_pop(radio->msg_queue); @@ -1719,8 +1708,6 @@ static int __mmradio_prepare_radio_device(mm_radio_t *radio) ret = mm_resource_manager_commit(radio->resource_manager); if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) { MMRADIO_LOG_ERROR("failed to commit resource manager"); - mm_resource_manager_mark_for_release(radio->resource_manager, - radio->radio_resource); radio->radio_resource = NULL; return ret; } |