Skip to content

Commit

Permalink
lib: xilflash: Initialized Status variable to XST_FAILURE
Browse files Browse the repository at this point in the history
Status variable in most of the xilflash functions were either
not initialized or initialized to XST_SUCCESS. This presents
a security violation which could cause the function to return
incorrect Status.

This patch fixes the issue by initialized Status variable to
XST_FAILURE.

Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>

Acked-for-series: Srinivas Goud <srinivas.goud@xilinx.com>

Acked-for-series: Srinivas Goud <srinivas.goud@xilinx.com>
  • Loading branch information
Amit Kumar Mahapatra authored and saddepal committed Sep 13, 2019
1 parent b9a283e commit fbbf7d5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 36 deletions.
Expand Up @@ -43,6 +43,7 @@
* 2.00a ktn 12/04/09 Updated to use the HAL processor APIs/macros
* 3.00a sdm 03/03/11 Updated to pass BaseAddress and Flash Width to _Initialize
* API, as required by the new version of the library
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
*</pre>
******************************************************************************/

Expand Down Expand Up @@ -109,7 +110,7 @@ XFlash FlashInstance; /* XFlash Instance. */
******************************************************************************/
int main(void)
{
int Status;
int Status = XST_FAILURE;

Status = FlashDeviceControlExample();
if(Status != XST_SUCCESS) {
Expand All @@ -134,7 +135,7 @@ int main(void)
******************************************************************************/
int FlashDeviceControlExample(void)
{
int Status;
int Status = XST_FAILURE;
u32 Index;
DeviceCtrlParam IoctlParams;

Expand Down
Expand Up @@ -46,6 +46,7 @@
* 2.00a ktn 12/04/09 Updated to use the HAL processor APIs/macros
* 3.00a sdm 03/03/11 Updated to pass BaseAddress and Flash Width to _Initialize
* API, as required by the new version of the library
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
*</pre>
******************************************************************************/

Expand Down Expand Up @@ -123,7 +124,7 @@ u8 WriteBuffer[FLASH_TEST_SIZE]; /* Write buffer. */
******************************************************************************/
int main(void)
{
int Status;
int Status = XST_FAILURE;

Status = PlatformFlashReadWriteExample();
if(Status != XST_SUCCESS) {
Expand All @@ -147,7 +148,7 @@ int main(void)
******************************************************************************/
int PlatformFlashReadWriteExample(void)
{
int Status;
int Status = XST_FAILURE;
u32 Index;
DeviceCtrlParam IoctlParams;

Expand Down
Expand Up @@ -59,6 +59,7 @@
* 4.2 nsk 01/29/16 Added Support to change Flash to Async Mode, if it was
* set to sync mode.
* Modified FLASH_BASE_ADDRESS to canonical name.
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
*</pre>
******************************************************************************/

Expand Down Expand Up @@ -145,7 +146,7 @@ u8 WriteBuffer[FLASH_TEST_SIZE]; /* Write buffer. */
******************************************************************************/
int main(void)
{
int Status;
int Status = XST_FAILURE;

Status = FlashProtectionExample();
if(Status != XST_SUCCESS) {
Expand All @@ -169,7 +170,7 @@ int main(void)
******************************************************************************/
int FlashProtectionExample(void)
{
int Status;
int Status = XST_FAILURE;
u32 Index;

#ifdef XPAR_XFL_DEVICE_FAMILY_INTEL
Expand Down
Expand Up @@ -63,6 +63,7 @@
* set to sync mode.
* Modified FLASH_BASE_ADDRESS to canonical name.
* 4.2 nsk 01/27/16 Added check to unlock the Micron G18 Flash.
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
*
*</pre>
******************************************************************************/
Expand Down Expand Up @@ -148,7 +149,7 @@ u8 WriteBuffer[FLASH_TEST_SIZE]; /* Write buffer. */
******************************************************************************/
int main(void)
{
int Status;
int Status = XST_FAILURE;

Status = FlashReadWriteExample();
if(Status != XST_SUCCESS) {
Expand All @@ -174,7 +175,7 @@ int main(void)
******************************************************************************/
int FlashReadWriteExample(void)
{
int Status;
int Status = XST_FAILURE;
u32 Index;

#ifdef XPAR_XFL_DEVICE_FAMILY_INTEL
Expand Down
1 change: 1 addition & 0 deletions lib/sw_services/xilflash/src/include/xilflash.h
Expand Up @@ -216,6 +216,7 @@
* 4.6 akm 01/22/19 Fixed compilation errors (CR#1018603)
* 4.7 akm 07/10/19 Updated XFlashAmd_Write() to use adjusted base address
* in write operation(CR-1029074).
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
* </pre>
*
***************************************************************************/
Expand Down
32 changes: 17 additions & 15 deletions lib/sw_services/xilflash/src/xilflash_amd.c
Expand Up @@ -76,6 +76,7 @@
* (CR 781697).
* 4.7 akm 07/10/19 Updated XFlashAmd_Write() to use adjusted base address
* in write operation(CR-1029074).
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
* </pre>
*
******************************************************************************/
Expand Down Expand Up @@ -574,7 +575,7 @@ int XFlashAmd_Read(XFlash *InstancePtr, u32 Offset, u32 Bytes, void *DestPtr)
******************************************************************************/
int XFlashAmd_Write(XFlash * InstancePtr, u32 Offset, u32 Bytes, void *SrcPtr)
{
int Status;
int Status = (int)XST_FAILURE;
u32 StartOffset;
u32 EndOffset;
XFlashVendorData_Amd *DevDataPtr;
Expand Down Expand Up @@ -653,7 +654,7 @@ int XFlashAmd_Erase(XFlash * InstancePtr, u32 Offset, u32 Bytes)
u32 Dummy;
u32 StartOffset;
u32 EndOffset;
int Status;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;
XFlashVendorData_Amd *DevDataPtr;

Expand Down Expand Up @@ -756,7 +757,7 @@ int XFlashAmd_Lock(XFlash * InstancePtr, u32 Offset, u32 Bytes)
u32 BaseAddress;
u32 BlockAddress;
u32 GroupAddress;
int Status;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;
XFlashVendorData_Amd *DevDataPtr;

Expand Down Expand Up @@ -882,7 +883,7 @@ int XFlashAmd_Unlock(XFlash * InstancePtr, u32 Offset, u32 Bytes)
u32 BaseAddress;
u32 Index;
u32 GroupAddress;
int Status = XST_FAILURE;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;
XFlashVendorData_Amd *DevDataPtr;

Expand Down Expand Up @@ -1080,7 +1081,7 @@ int XFlashAmd_Unlock(XFlash * InstancePtr, u32 Offset, u32 Bytes)
******************************************************************************/
int XFlashAmd_EraseChip(XFlash * InstancePtr)
{
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;
XFlashVendorData_Amd *DevDataPtr;

Expand Down Expand Up @@ -1143,7 +1144,7 @@ int XFlashAmd_EraseChip(XFlash * InstancePtr)

int XFlashAmd_Reset(XFlash * InstancePtr)
{
int Status;
int Status = (int)XST_FAILURE;

/*
* Verify inputs are valid.
Expand Down Expand Up @@ -1183,7 +1184,8 @@ static int XFlashAmd_ResetBank(XFlash * InstancePtr, u32 Offset, u32 Bytes)
{
XFlashVendorData_Amd *DevDataPtr;
u16 Region, Block;
u32 Dummy, Status;
u32 Dummy;
u32 Status = (u32)XST_FAILURE;
XFlashGeometry *GeomPtr;

/*
Expand Down Expand Up @@ -1256,7 +1258,7 @@ int XFlashAmd_DeviceControl(XFlash * InstancePtr, u32 Command,
{
u32 BlockAddr;
u32 Offset;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr;

/*
Expand Down Expand Up @@ -1543,7 +1545,7 @@ static int WriteBuffer8(XFlash * InstancePtr, void *DestPtr,
u8 *DestinationPtr = (u8*)DestPtr;
u32 BaseAddress;
u32 Index = 0;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down Expand Up @@ -1615,7 +1617,7 @@ static int WriteBuffer8(XFlash * InstancePtr, void *DestPtr,
static int WriteBuffer16(XFlash * InstancePtr, void *DestPtr,
void *SrcPtr, u32 Bytes)
{
u32 Status;
u32 Status = (u32)XST_FAILURE;
u16 *SrcWordPtr = (u16*)SrcPtr;
u16 *DestWordPtr = (u16*)DestPtr;

Expand Down Expand Up @@ -1663,7 +1665,7 @@ static int WriteBufferSpansion(XFlash * InstancePtr, void *DestPtr,
u32 BaseAddress= InstancePtr->Geometry.BaseAddress;
u16* Tempsrcptr = (u16 *)SrcPtr;
u32 Index = 0;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr = GET_PARTDATA(InstancePtr);
u32 BufferSize = InstancePtr->Properties.ProgCap.WriteBufferSize;

Expand Down Expand Up @@ -1721,7 +1723,7 @@ static int WriteBufferAmd(XFlash * InstancePtr, void *DestPtr,
u32 DestinationPtr = (u32)DestPtr;
u32 BaseAddress = InstancePtr->Geometry.BaseAddress;
u32 Index = 0;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr = GET_PARTDATA(InstancePtr);

/* Send the Unlock Bypass command. */
Expand Down Expand Up @@ -1789,7 +1791,7 @@ int WriteSingleBuffer(XFlash * InstancePtr, void *DestPtr,
u32 DestinationPtr = (u32)DestPtr;
u32 BaseAddress;
u32 Index = 0;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr;
u32 SectorAddress;
u32 WordCount = Bytes/2;
Expand Down Expand Up @@ -1881,7 +1883,7 @@ static int WriteBuffer32(XFlash * InstancePtr, void *DestPtr,
u32 *DestinationPtr = (u32*)DestPtr;
u32 BaseAddress;
u32 Index = 0;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
XFlashVendorData_Amd *DevDataPtr;

/*
Expand Down Expand Up @@ -2555,7 +2557,7 @@ static int CheckBlockProtection(XFlash * InstancePtr, u32 Offset)
u32 BlockAddress;
u32 CmdAddress;
u32 ProtStatus;
int Status;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;
XFlashVendorData_Amd *DevDataPtr;

Expand Down
3 changes: 2 additions & 1 deletion lib/sw_services/xilflash/src/xilflash_cfi.c
Expand Up @@ -79,6 +79,7 @@
* fails to work.
* 3.04a srt 02/18/13 Fixed CR 700553.
* 4.5 tjs 08/13/18 Fixed compilation errors for ARMCC (CR#1008306)
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
* </pre>
*
*
Expand Down Expand Up @@ -127,7 +128,7 @@ int XFlashCFI_ReadCommon(XFlash *InstancePtr, u8 BusWidth)
{
void *DataPtr;
u32 BaseAddress;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u8 Data8;
u8 Mode;
u8 DataQRY[3];
Expand Down
25 changes: 13 additions & 12 deletions lib/sw_services/xilflash/src/xilflash_intel.c
Expand Up @@ -91,6 +91,7 @@
* Description: Non-word aligned data write to flash fails
* with AXI interface.
* 4.1 nsk 08/06/15 Fixed CR 835008.
* 4.7 akm 07/23/19 Initialized Status variable to XST_FAILURE.
* </pre>
*
******************************************************************************/
Expand Down Expand Up @@ -432,7 +433,7 @@ int XFlashIntel_Read(XFlash *InstancePtr, u32 Offset, u32 Bytes, void *DestPtr)
int XFlashIntel_Write(XFlash *InstancePtr, u32 Offset, u32 Bytes, void *SrcPtr)
{
XFlashVendorData_Intel *DevDataPtr;
int Status;
int Status = (int)XST_FAILURE;

/*
* Verify inputs are valid.
Expand Down Expand Up @@ -503,7 +504,7 @@ int XFlashIntel_Erase(XFlash *InstancePtr, u32 Offset, u32 Bytes)
u32 Dummy;
XFlashGeometry *GeomPtr;
XFlashVendorData_Intel *DevDataPtr;
int Status;
int Status = (int)XST_FAILURE;

/*
* Verify inputs are valid.
Expand Down Expand Up @@ -601,7 +602,7 @@ int XFlashIntel_Lock(XFlash *InstancePtr, u32 Offset, u32 Bytes)
u32 Dummy;
u32 BaseAddress;
u32 BlockAddress;
int Status;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;

/*
Expand Down Expand Up @@ -746,7 +747,7 @@ int XFlashIntel_Unlock(XFlash *InstancePtr, u32 Offset, u32 Bytes)
u32 Dummy;
u32 BaseAddress;
u32 BlockAddress;
int Status;
int Status = (int)XST_FAILURE;
XFlashGeometry *GeomPtr;

/*
Expand Down Expand Up @@ -919,7 +920,7 @@ int XFlashIntel_Reset(XFlash *InstancePtr)
static int XFlashIntel_ResetBank(XFlash *InstancePtr, u32 Offset, u32 Bytes)
{
XFlashVendorData_Intel *DevDataPtr;
int Status;
int Status = (int)XST_FAILURE;
u16 Region, Block;
u32 BaseAddress;
u32 Dummy;
Expand Down Expand Up @@ -1029,7 +1030,7 @@ static int XFlashIntel_ResetBank(XFlash *InstancePtr, u32 Offset, u32 Bytes)
int XFlashIntel_DeviceControl(XFlash *InstancePtr, u32 Command,
DeviceCtrlParam *Parameters)
{
int Status;
int Status = (int)XST_FAILURE;
XFlashVendorData_Intel *DevDataPtr;

/*
Expand Down Expand Up @@ -1703,7 +1704,7 @@ static int WriteBuffer8(XFlash *InstancePtr, void *DestPtr,
u32 BaseAddress;
u32 PartialBytes;
u32 Count;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u32 Index;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down Expand Up @@ -1944,7 +1945,7 @@ static int WriteBufferStrataFlashDevice(XFlash *InstancePtr, void *DestPtr,
u32 BytesLeft = Bytes;
u32 PartialBytes;
u32 Count;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u32 Index;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down Expand Up @@ -2197,7 +2198,7 @@ static int WriteBufferIntelFlashDevice(XFlash *InstancePtr, void *DestPtr,
u32 BytesLeft = Bytes;
u32 PartialBytes;
u32 Count;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u32 Index;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down Expand Up @@ -2446,7 +2447,7 @@ static int WriteBufferIntelFlashDevice(XFlash *InstancePtr, void *DestPtr,
static int WriteBuffer16(XFlash *InstancePtr, void *DestPtr,
void *SrcPtr, u32 Bytes)
{
u32 Status;
u32 Status = (u32)XST_FAILURE;
if (InstancePtr->Properties.PartID.DeviceID == 0x01) {
Status = WriteBufferStrataFlashDevice(InstancePtr, DestPtr,
SrcPtr, Bytes);
Expand Down Expand Up @@ -2507,7 +2508,7 @@ static int WriteBuffer32(XFlash *InstancePtr, void *DestPtr,
u32 BytesLeft = Bytes;
u32 PartialBytes;
u32 Count;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u32 Index;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down Expand Up @@ -2816,7 +2817,7 @@ static int WriteBuffer64(XFlash *InstancePtr, void *DestPtr,
u32 BytesLeft = Bytes;
u32 PartialBytes;
u32 Count;
int Status = XST_SUCCESS;
int Status = (int)XST_FAILURE;
u32 Index;

DevDataPtr = GET_PARTDATA(InstancePtr);
Expand Down

0 comments on commit fbbf7d5

Please sign in to comment.