Skip to content

Commit

Permalink
Fix nasa#1755, separate variable for PSP status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Aug 17, 2021
1 parent b66f476 commit 42897cf
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 42 deletions.
29 changes: 16 additions & 13 deletions modules/es/fsw/src/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int32 CFE_ES_CDS_EarlyInit(void)
size_t MinRequiredSize;
int32 OsStatus;
int32 Status;
int32 PspStatus;

CFE_ES_Global.CDSIsAvailable = false;

Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}

/*----------------------------------------------------------------
Expand Down Expand Up @@ -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 */
Expand All @@ -823,17 +826,17 @@ 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);
}
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;
}

Expand Down
18 changes: 13 additions & 5 deletions modules/es/fsw/src/cfe_es_cds_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions modules/es/fsw/src/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down
17 changes: 8 additions & 9 deletions modules/es/fsw/src/cfe_es_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions modules/es/fsw/src/cfe_es_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -4300,7 +4300,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);
Expand Down Expand Up @@ -4539,11 +4539,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);
Expand Down
8 changes: 5 additions & 3 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions modules/time/fsw/src/cfe_time_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 42897cf

Please sign in to comment.