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 | |
parent | 1d1f94b1bcc4a2c371e3ab8744fbb134362efb84 (diff) | |
download | libmm-radio-a672edbba43f24d0ff70dc83f2413fde6a478dd4.tar.gz libmm-radio-a672edbba43f24d0ff70dc83f2413fde6a478dd4.tar.bz2 libmm-radio-a672edbba43f24d0ff70dc83f2413fde6a478dd4.zip |
Fix coverity/Svace issues (BAD_CHECK_OF_WAIT_COND, MISSING_UNLOCK, NULL_AFTER_DEREF)accepted/tizen/unified/x/20240205.063846accepted/tizen/unified/toolchain/20240311.065435accepted/tizen/unified/dev/20240620.005512accepted/tizen/unified/20240131.175405
- 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')
-rw-r--r-- | src/include/mm_radio_priv_hal.h | 3 | ||||
-rw-r--r-- | src/include/mm_radio_utils.h | 3 | ||||
-rw-r--r-- | src/mm_radio_priv_emulator.c | 16 | ||||
-rw-r--r-- | src/mm_radio_priv_hal.c | 55 |
4 files changed, 25 insertions, 52 deletions
diff --git a/src/include/mm_radio_priv_hal.h b/src/include/mm_radio_priv_hal.h index 6221545..b8185c4 100644 --- a/src/include/mm_radio_priv_hal.h +++ b/src/include/mm_radio_priv_hal.h @@ -198,9 +198,6 @@ typedef struct { int freq; - /* command lock */ - pthread_mutex_t volume_lock; - float local_volume; /* region settings */ diff --git a/src/include/mm_radio_utils.h b/src/include/mm_radio_utils.h index c72da4a..759ef71 100644 --- a/src/include/mm_radio_utils.h +++ b/src/include/mm_radio_utils.h @@ -125,9 +125,6 @@ do { \ #define MMRADIO_CMD_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->cmd_lock) #define MMRADIO_CMD_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->cmd_lock) -#define MMRADIO_VOLUME_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->volume_lock) -#define MMRADIO_VOLUME_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->volume_lock) - /* msg/seek/scan thread */ #define MMRADIO_THREAD_LOCK(x_thread_t) pthread_mutex_lock(&x_thread_t->mutex) #define MMRADIO_THREAD_UNLOCK(x_thread_t) pthread_mutex_unlock(&x_thread_t->mutex) diff --git a/src/mm_radio_priv_emulator.c b/src/mm_radio_priv_emulator.c index d7f6cd1..8d899ba 100644 --- a/src/mm_radio_priv_emulator.c +++ b/src/mm_radio_priv_emulator.c @@ -1557,14 +1557,10 @@ static void __mmradio_destroy_thread_type(mm_radio_t *radio, MMRadioThreadTypes switch (type) { case MM_RADIO_THREAD_MSG: msg = g_slice_new0(mm_radio_msg_t); - if (!msg) { - MMRADIO_LOG_ERROR("failed to get mm_radio_msg_t"); - } else { - msg->msg_type = MM_RADIO_MSG_DESTROY; - g_async_queue_push_front(radio->msg_queue, msg); - pthread_join(p_thread->thread, NULL); - p_thread->thread = 0; - } + msg->msg_type = MM_RADIO_MSG_DESTROY; + g_async_queue_push_front(radio->msg_queue, msg); + pthread_join(p_thread->thread, NULL); + p_thread->thread = 0; break; case MM_RADIO_THREAD_SEEK: case MM_RADIO_THREAD_SCAN: @@ -1608,10 +1604,6 @@ static void __mmradio_destroy_threads(mm_radio_t *radio) void __mmradio_msg_push(mm_radio_t *radio, MMRadioMsgTypes msg_type, int msg_data) { mm_radio_msg_t *msg = g_slice_new0(mm_radio_msg_t); - if (!msg) { - MMRADIO_LOG_ERROR("NULL msg pointer"); - return; - } msg->msg_type = msg_type; msg->data = msg_data; 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; } |