From 97bb81a998fc7e210e01bb11ed551dcad134eca2 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Sat, 12 Oct 2024 21:09:43 +0200 Subject: [PATCH] Fix #1335, Combine redundant switch case to simplify CFE_ES_CleanupObjectCallback --- modules/es/fsw/src/cfe_es_apps.c | 62 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/modules/es/fsw/src/cfe_es_apps.c b/modules/es/fsw/src/cfe_es_apps.c index f4f2101ff..0e60281c9 100644 --- a/modules/es/fsw/src/cfe_es_apps.c +++ b/modules/es/fsw/src/cfe_es_apps.c @@ -1565,6 +1565,7 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg) int32 OsStatus; osal_objtype_t ObjType; bool ObjIsValid; + CFE_Status_t ErrorStatus; CleanState = (CFE_ES_CleanupState_t *)arg; ObjIsValid = true; @@ -1573,32 +1574,41 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg) switch (ObjType) { case OS_OBJECT_TYPE_OS_TASK: - OsStatus = OS_TaskDelete(ObjectId); + OsStatus = OS_TaskDelete(ObjectId); + ErrorStatus = CFE_ES_ERR_CHILD_TASK_DELETE; break; case OS_OBJECT_TYPE_OS_QUEUE: - OsStatus = OS_QueueDelete(ObjectId); + OsStatus = OS_QueueDelete(ObjectId); + ErrorStatus = CFE_ES_QUEUE_DELETE_ERR; break; case OS_OBJECT_TYPE_OS_BINSEM: - OsStatus = OS_BinSemDelete(ObjectId); + OsStatus = OS_BinSemDelete(ObjectId); + ErrorStatus = CFE_ES_BIN_SEM_DELETE_ERR; break; case OS_OBJECT_TYPE_OS_COUNTSEM: - OsStatus = OS_CountSemDelete(ObjectId); + OsStatus = OS_CountSemDelete(ObjectId); + ErrorStatus = CFE_ES_COUNT_SEM_DELETE_ERR; break; case OS_OBJECT_TYPE_OS_MUTEX: - OsStatus = OS_MutSemDelete(ObjectId); + OsStatus = OS_MutSemDelete(ObjectId); + ErrorStatus = CFE_ES_MUT_SEM_DELETE_ERR; break; case OS_OBJECT_TYPE_OS_TIMECB: - OsStatus = OS_TimerDelete(ObjectId); + OsStatus = OS_TimerDelete(ObjectId); + ErrorStatus = CFE_ES_TIMER_DELETE_ERR; break; case OS_OBJECT_TYPE_OS_STREAM: - OsStatus = OS_close(ObjectId); + OsStatus = OS_close(ObjectId); + ErrorStatus = CFE_ES_APP_CLEANUP_ERR; break; case OS_OBJECT_TYPE_OS_MODULE: - OsStatus = OS_ModuleUnload(ObjectId); + OsStatus = OS_ModuleUnload(ObjectId); + ErrorStatus = CFE_ES_APP_CLEANUP_ERR; break; default: - ObjIsValid = false; - OsStatus = OS_ERROR; + ObjIsValid = false; + OsStatus = OS_ERROR; + ErrorStatus = CFE_ES_APP_CLEANUP_ERR; break; } @@ -1615,36 +1625,8 @@ void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg) OS_ObjectIdToInteger(ObjectId), (long)OsStatus); if (CleanState->OverallStatus == CFE_SUCCESS) { - /* - * Translate any OS failures into the appropriate CFE_ES return codes - * (Some object types have special return codes, depending on what type - * of object failed to delete) - */ - switch (ObjType) - { - case OS_OBJECT_TYPE_OS_TASK: - CleanState->OverallStatus = CFE_ES_ERR_CHILD_TASK_DELETE; - break; - case OS_OBJECT_TYPE_OS_QUEUE: - CleanState->OverallStatus = CFE_ES_QUEUE_DELETE_ERR; - break; - case OS_OBJECT_TYPE_OS_BINSEM: - CleanState->OverallStatus = CFE_ES_BIN_SEM_DELETE_ERR; - break; - case OS_OBJECT_TYPE_OS_COUNTSEM: - CleanState->OverallStatus = CFE_ES_COUNT_SEM_DELETE_ERR; - break; - case OS_OBJECT_TYPE_OS_MUTEX: - CleanState->OverallStatus = CFE_ES_MUT_SEM_DELETE_ERR; - break; - case OS_OBJECT_TYPE_OS_TIMECB: - CleanState->OverallStatus = CFE_ES_TIMER_DELETE_ERR; - break; - default: - /* generic failure */ - CleanState->OverallStatus = CFE_ES_APP_CLEANUP_ERR; - break; - } + // Save the object-type-specific error code that was set earlier in each case in the switch statement + CleanState->OverallStatus = ErrorStatus; } } }