From 62f2b9c8dd87c2a9b1a0bc74aa11582992e7dde3 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 3 Aug 2021 18:12:57 -0500 Subject: [PATCH] Fix #1755, separate variable for PSP status Ensure a separate stack variable, always named "PspStatus", is used to hold the result of a PSP API call. Do not use the same variable that is used to store a CFE status code. --- modules/es/fsw/src/cfe_es_cds.c | 29 ++++++++++++++----------- modules/es/fsw/src/cfe_es_cds_mempool.c | 18 ++++++++++----- modules/es/fsw/src/cfe_es_erlog.c | 10 +++++---- modules/es/fsw/src/cfe_es_start.c | 17 +++++++-------- modules/es/fsw/src/cfe_es_task.c | 5 +++-- modules/es/ut-coverage/es_UT.c | 6 ++--- modules/evs/fsw/src/cfe_evs_task.c | 8 ++++--- modules/time/fsw/src/cfe_time_utils.c | 6 ++--- 8 files changed, 57 insertions(+), 42 deletions(-) diff --git a/modules/es/fsw/src/cfe_es_cds.c b/modules/es/fsw/src/cfe_es_cds.c index 07104638e..2604b6c2e 100644 --- a/modules/es/fsw/src/cfe_es_cds.c +++ b/modules/es/fsw/src/cfe_es_cds.c @@ -59,6 +59,7 @@ int32 CFE_ES_CDS_EarlyInit(void) size_t MinRequiredSize; int32 OsStatus; int32 Status; + int32 PspStatus; CFE_ES_Global.CDSIsAvailable = false; @@ -74,12 +75,13 @@ int32 CFE_ES_CDS_EarlyInit(void) /* Get CDS size from PSP. Note that the PSP interface * uses "uint32" for size here. */ - Status = CFE_PSP_GetCDSSize(&PlatformSize); - if (Status != CFE_PSP_SUCCESS) + PspStatus = CFE_PSP_GetCDSSize(&PlatformSize); + if (PspStatus != CFE_PSP_SUCCESS) { /* Error getting the size of the CDS from the BSP */ - CFE_ES_WriteToSysLog("%s: Unable to obtain CDS Size from BSP (Err=0x%08X)\n", __func__, (unsigned int)Status); - return Status; + CFE_ES_WriteToSysLog("%s: Unable to obtain CDS Size from BSP (Err=0x%08X)\n", __func__, + (unsigned int)PspStatus); + return CFE_STATUS_EXTERNAL_RESOURCE_FAIL; } /* Always truncate the size to the nearest 4 byte boundary */ @@ -655,18 +657,18 @@ int32 CFE_ES_InitCDSRegistry(void) int32 CFE_ES_UpdateCDSRegistry(void) { CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; - int32 Status; + int32 PspStatus; /* Copy the contents of the local registry to the CDS */ - Status = CFE_PSP_WriteToCDS(CDS->Registry, CDS_REG_OFFSET, sizeof(CDS->Registry)); + PspStatus = CFE_PSP_WriteToCDS(CDS->Registry, CDS_REG_OFFSET, sizeof(CDS->Registry)); - if (Status != CFE_PSP_SUCCESS) + if (PspStatus != CFE_PSP_SUCCESS) { - CFE_ES_WriteToSysLog("%s: Failed to write CDS Registry. Status=0x%08X\n", __func__, (unsigned int)Status); - Status = CFE_ES_CDS_ACCESS_ERROR; + CFE_ES_WriteToSysLog("%s: Failed to write CDS Registry. Status=0x%08X\n", __func__, (unsigned int)PspStatus); + return CFE_ES_CDS_ACCESS_ERROR; } - return Status; + return CFE_SUCCESS; } /*---------------------------------------------------------------- @@ -803,6 +805,7 @@ int32 CFE_ES_RebuildCDS(void) { CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; int32 Status; + int32 PspStatus; /* First, determine if the CDS registry stored in the CDS is smaller or equal */ /* in size to the CDS registry we are currently configured for */ @@ -823,9 +826,9 @@ int32 CFE_ES_RebuildCDS(void) return CFE_ES_CDS_INVALID; } - Status = CFE_PSP_ReadFromCDS(&CDS->Registry, CDS_REG_OFFSET, sizeof(CDS->Registry)); + PspStatus = CFE_PSP_ReadFromCDS(&CDS->Registry, CDS_REG_OFFSET, sizeof(CDS->Registry)); - if (Status == CFE_PSP_SUCCESS) + if (PspStatus == CFE_PSP_SUCCESS) { /* Scan the memory pool and identify the created but currently unused memory blocks */ Status = CFE_ES_RebuildCDSPool(CDS->DataSize, CDS_POOL_OFFSET); @@ -833,7 +836,7 @@ int32 CFE_ES_RebuildCDS(void) else { /* Registry in CDS is unreadable */ - CFE_ES_WriteToSysLog("%s: Registry in CDS is unreadable, PSP error %lx\n", __func__, (unsigned long)Status); + CFE_ES_WriteToSysLog("%s: Registry in CDS is unreadable, PSP error %lx\n", __func__, (unsigned long)PspStatus); Status = CFE_ES_CDS_INVALID; } diff --git a/modules/es/fsw/src/cfe_es_cds_mempool.c b/modules/es/fsw/src/cfe_es_cds_mempool.c index 2c041c084..e3c94f940 100644 --- a/modules/es/fsw/src/cfe_es_cds_mempool.c +++ b/modules/es/fsw/src/cfe_es_cds_mempool.c @@ -183,6 +183,7 @@ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite) CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; char LogMessage[CFE_ES_MAX_SYSLOG_MSG_SIZE]; int32 Status; + int32 PspStatus; size_t BlockSize; size_t UserDataSize; size_t UserDataOffset; @@ -239,12 +240,14 @@ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite) } else { - Status = CFE_PSP_WriteToCDS(DataToWrite, UserDataOffset, UserDataSize); - if (Status != CFE_PSP_SUCCESS) + PspStatus = CFE_PSP_WriteToCDS(DataToWrite, UserDataOffset, UserDataSize); + if (PspStatus != CFE_PSP_SUCCESS) { snprintf(LogMessage, sizeof(LogMessage), - "Err writing user data to CDS (Stat=0x%08x) @Offset=0x%08lx\n", (unsigned int)Status, + "Err writing user data to CDS (Stat=0x%08x) @Offset=0x%08lx\n", (unsigned int)PspStatus, (unsigned long)UserDataOffset); + + Status = CFE_ES_CDS_ACCESS_ERROR; } } } @@ -277,6 +280,7 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle) { CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; int32 Status; + int32 PspStatus; uint32 CrcOfCDSData; size_t BlockSize; size_t UserDataSize; @@ -319,8 +323,8 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle) if (Status == CFE_SUCCESS) { /* Read the data block */ - Status = CFE_PSP_ReadFromCDS(DataRead, UserDataOffset, UserDataSize); - if (Status == CFE_PSP_SUCCESS) + PspStatus = CFE_PSP_ReadFromCDS(DataRead, UserDataOffset, UserDataSize); + if (PspStatus == CFE_PSP_SUCCESS) { /* Compute the CRC for the data read from the CDS and determine if the data is still valid */ CrcOfCDSData = CFE_ES_CalculateCRC(DataRead, UserDataSize, 0, CFE_MISSION_ES_DEFAULT_CRC); @@ -335,6 +339,10 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle) Status = CFE_SUCCESS; } } + else + { + Status = CFE_ES_CDS_ACCESS_ERROR; + } } } } diff --git a/modules/es/fsw/src/cfe_es_erlog.c b/modules/es/fsw/src/cfe_es_erlog.c index 841918b0a..93d3831be 100644 --- a/modules/es/fsw/src/cfe_es_erlog.c +++ b/modules/es/fsw/src/cfe_es_erlog.c @@ -282,6 +282,7 @@ void CFE_ES_BackgroundERLogFileEventHandler(void *Meta, CFE_FS_FileWriteEvent_t bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg) { int32 Status; + int32 PspStatus; uint32 PspContextId; char ReasonString[CFE_ES_ERLOG_DESCRIPTION_MAX_LENGTH]; CFE_ES_TaskInfo_t EsTaskInfo; @@ -302,11 +303,12 @@ bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg) */ ResetType = 0; memset(&EsTaskInfo, 0, sizeof(EsTaskInfo)); - Status = CFE_PSP_Exception_GetSummary(&PspContextId, &ExceptionTaskID, ReasonString, sizeof(ReasonString)); - if (Status != CFE_PSP_SUCCESS) + PspStatus = CFE_PSP_Exception_GetSummary(&PspContextId, &ExceptionTaskID, ReasonString, sizeof(ReasonString)); + if (PspStatus != CFE_PSP_SUCCESS) { - /* reason string is not available - populate with something for the log */ - snprintf(ReasonString, sizeof(ReasonString), "Unknown - CFE_PSP_ExceptionGetSummary() error %ld", (long)Status); + /* reason string is not available - populate with something for the PspStatus*/ + snprintf(ReasonString, sizeof(ReasonString), "Unknown - CFE_PSP_ExceptionGetSummary() error %ld", + (long)PspStatus); PspContextId = 0; ExceptionTaskID = OS_OBJECT_ID_UNDEFINED; } /* end if */ diff --git a/modules/es/fsw/src/cfe_es_start.c b/modules/es/fsw/src/cfe_es_start.c index 996e40e90..f20a1fa3e 100644 --- a/modules/es/fsw/src/cfe_es_start.c +++ b/modules/es/fsw/src/cfe_es_start.c @@ -248,25 +248,24 @@ void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const cha *-----------------------------------------------------------------*/ void CFE_ES_SetupResetVariables(uint32 StartType, uint32 StartSubtype, uint32 BootSource) { - - int32 status; + int32 PspStatus; uint32 resetAreaSize; cpuaddr ResetDataAddr; /* ** Get the pointer to the Reset area from the BSP */ - status = CFE_PSP_GetResetArea(&ResetDataAddr, &resetAreaSize); + PspStatus = CFE_PSP_GetResetArea(&ResetDataAddr, &resetAreaSize); /* ** Make sure the status is OK or size is big enough */ - if (status != CFE_PSP_SUCCESS) + if (PspStatus != CFE_PSP_SUCCESS) { /* ** Cannot use the ES System log without the Reset Area */ - OS_printf("ES Startup: CFE_PSP_GetResetArea call Failed (0x%08x)!\n", (unsigned int)status); + OS_printf("ES Startup: CFE_PSP_GetResetArea call Failed (0x%08x)!\n", (unsigned int)PspStatus); /* ** Delay to allow the message to be read @@ -477,7 +476,7 @@ void CFE_ES_SetupResetVariables(uint32 StartType, uint32 StartSubtype, uint32 Bo void CFE_ES_InitializeFileSystems(uint32 StartType) { int32 OsStatus; - int32 RetStatus; + int32 PspStatus; cpuaddr RamDiskMemoryAddress; uint32 RamDiskMemorySize; int32 PercentFree; @@ -486,12 +485,12 @@ void CFE_ES_InitializeFileSystems(uint32 StartType) /* ** Get the memory area for the RAM disk */ - RetStatus = CFE_PSP_GetVolatileDiskMem(&(RamDiskMemoryAddress), &(RamDiskMemorySize)); + PspStatus = CFE_PSP_GetVolatileDiskMem(&(RamDiskMemoryAddress), &(RamDiskMemorySize)); - if (RetStatus != CFE_PSP_SUCCESS) + if (PspStatus != CFE_PSP_SUCCESS) { CFE_ES_WriteToSysLog("%s: Cannot Get Memory for Volatile Disk. EC = 0x%08X\n", __func__, - (unsigned int)RetStatus); + (unsigned int)PspStatus); /* ** Delay to allow the message to be read diff --git a/modules/es/fsw/src/cfe_es_task.c b/modules/es/fsw/src/cfe_es_task.c index 72c4f0e94..be57dd130 100644 --- a/modules/es/fsw/src/cfe_es_task.c +++ b/modules/es/fsw/src/cfe_es_task.c @@ -357,6 +357,7 @@ void CFE_ES_GenerateBuildInfoEvents(void) int32 CFE_ES_TaskInit(void) { int32 Status; + int32 PspStatus; uint32 SizeofCfeSegment; cpuaddr CfeSegmentAddr; uint8 VersionNumber[4]; @@ -442,9 +443,9 @@ int32 CFE_ES_TaskInit(void) ** Compute the CRC for the cfe core code segment and place ** in ES Housekeeping pkt. */ - Status = CFE_PSP_GetCFETextSegmentInfo(&CfeSegmentAddr, &SizeofCfeSegment); + PspStatus = CFE_PSP_GetCFETextSegmentInfo(&CfeSegmentAddr, &SizeofCfeSegment); - if (Status == CFE_PSP_SUCCESS) + if (PspStatus == CFE_PSP_SUCCESS) { CFE_ES_Global.TaskData.HkPacket.Payload.CFECoreChecksum = CFE_ES_CalculateCRC((void *)(CfeSegmentAddr), SizeofCfeSegment, 0, CFE_MISSION_ES_DEFAULT_CRC); diff --git a/modules/es/ut-coverage/es_UT.c b/modules/es/ut-coverage/es_UT.c index c0c2de32a..443e10b3b 100644 --- a/modules/es/ut-coverage/es_UT.c +++ b/modules/es/ut-coverage/es_UT.c @@ -4280,7 +4280,7 @@ void TestCDS() /* Test CDS initialization with size not obtainable */ ES_ResetUnitTest(); UT_SetDefaultReturnValue(UT_KEY(CFE_PSP_GetCDSSize), -1); - UtAssert_INT32_EQ(CFE_ES_CDS_EarlyInit(), -1); + UtAssert_INT32_EQ(CFE_ES_CDS_EarlyInit(), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Reset back to a sufficient CDS size */ UT_SetCDSSize(128 * 1024); @@ -4519,11 +4519,11 @@ void TestCDSMempool(void) /* Test CDS block write with a CDS write error (data content) */ UT_SetDeferredRetcode(UT_KEY(CFE_PSP_WriteToCDS), 2, OS_ERROR); - UtAssert_INT32_EQ(CFE_ES_CDSBlockWrite(BlockHandle, &Data), OS_ERROR); + UtAssert_INT32_EQ(CFE_ES_CDSBlockWrite(BlockHandle, &Data), CFE_ES_CDS_ACCESS_ERROR); /* Test CDS block read with a CDS read error (data content) */ UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 3, OS_ERROR); - UtAssert_INT32_EQ(CFE_ES_CDSBlockRead(&Data, BlockHandle), OS_ERROR); + UtAssert_INT32_EQ(CFE_ES_CDSBlockRead(&Data, BlockHandle), CFE_ES_CDS_ACCESS_ERROR); /* Corrupt the data as to cause a CRC mismatch */ UT_GetDataBuffer(UT_KEY(CFE_PSP_ReadFromCDS), (void **)&CdsPtr, NULL, NULL); diff --git a/modules/evs/fsw/src/cfe_evs_task.c b/modules/evs/fsw/src/cfe_evs_task.c index 562b7f282..df4727d3e 100644 --- a/modules/evs/fsw/src/cfe_evs_task.c +++ b/modules/evs/fsw/src/cfe_evs_task.c @@ -64,6 +64,7 @@ int32 CFE_EVS_EarlyInit(void) { int32 OsStatus; int32 Status; + int32 PspStatus; uint32 resetAreaSize = 0; cpuaddr resetAreaAddr; CFE_ES_ResetData_t *CFE_EVS_ResetDataPtr = (CFE_ES_ResetData_t *)NULL; @@ -80,13 +81,14 @@ int32 CFE_EVS_EarlyInit(void) CFE_EVS_Global.EVS_TlmPkt.Payload.LogMode = CFE_PLATFORM_EVS_DEFAULT_LOG_MODE; /* Get a pointer to the CFE reset area from the BSP */ - Status = CFE_PSP_GetResetArea(&resetAreaAddr, &resetAreaSize); + PspStatus = CFE_PSP_GetResetArea(&resetAreaAddr, &resetAreaSize); /* Panic on error */ - if (Status != CFE_PSP_SUCCESS) + if (PspStatus != CFE_PSP_SUCCESS) { /* Can't log evs messages without the reset area */ - CFE_ES_WriteToSysLog("%s: Call to CFE_PSP_GetResetArea failed, RC=0x%08x\n", __func__, (unsigned int)Status); + Status = CFE_EVS_RESET_AREA_POINTER; + CFE_ES_WriteToSysLog("%s: Call to CFE_PSP_GetResetArea failed, RC=0x%08x\n", __func__, (unsigned int)PspStatus); /* Delay to allow message to be read */ OS_TaskDelay(CFE_EVS_PANIC_DELAY); diff --git a/modules/time/fsw/src/cfe_time_utils.c b/modules/time/fsw/src/cfe_time_utils.c index aee970c9d..6b096ee94 100644 --- a/modules/time/fsw/src/cfe_time_utils.c +++ b/modules/time/fsw/src/cfe_time_utils.c @@ -116,7 +116,7 @@ void CFE_TIME_QueryResetVars(void) CFE_TIME_ResetVars_t LocalResetVars; uint32 DefSubsMET; uint32 DefSubsSTCF; - int32 status; + int32 PspStatus; volatile CFE_TIME_ReferenceState_t *RefState; uint32 resetAreaSize; cpuaddr resetAreaAddr; @@ -127,9 +127,9 @@ void CFE_TIME_QueryResetVars(void) /* ** Get the pointer to the Reset area from the BSP */ - status = CFE_PSP_GetResetArea(&(resetAreaAddr), &(resetAreaSize)); + PspStatus = CFE_PSP_GetResetArea(&(resetAreaAddr), &(resetAreaSize)); - if (status != CFE_PSP_SUCCESS) + if (PspStatus != CFE_PSP_SUCCESS) { /* There is something wrong with the Reset Area */ CFE_TIME_Global.DataStoreStatus = CFE_TIME_RESET_AREA_BAD;