From 3580a10ae23bd77dc604a66cbcd6b1b733ac5bfc Mon Sep 17 00:00:00 2001 From: Shakti Bhatnagar Date: Thu, 16 Apr 2015 10:10:28 +0530 Subject: [PATCH] nandpsu_v1_0: Fixed triggering of assert call when block reaches max block. Since the check for the block to have reached the end block was at the end of the loop, thus assert call triggering could happen if the block crosses the max block limit, making the driver to hang. Thus to fix the triggering of assert call, the check for the block to have reached the max block is being done at the start of the loop in XNandPsu_CalculateLength function. The u32 typecasting for the variable OffsetVar has been removed and the data type for the variable TempLen has been changed to u64 as for higher block numbers the value for these variables will require u64 datatype otherwise corrupted value will get stored which will lead to wrong calculation of block. Signed-off-by: Shakti Bhatnagar --- .../drivers/nandpsu/src/xnandpsu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/XilinxProcessorIPLib/drivers/nandpsu/src/xnandpsu.c b/XilinxProcessorIPLib/drivers/nandpsu/src/xnandpsu.c index b8afcd3e..70161f78 100644 --- a/XilinxProcessorIPLib/drivers/nandpsu/src/xnandpsu.c +++ b/XilinxProcessorIPLib/drivers/nandpsu/src/xnandpsu.c @@ -1672,14 +1672,18 @@ static s32 XNandPsu_CalculateLength(XNandPsu *InstancePtr, u64 Offset, u32 BlockSize; u32 BlockLen; u32 Block; - u32 TempLen = 0; + u64 TempLen = 0; u64 OffsetVar = Offset; BlockSize = InstancePtr->Geometry.BlockSize; while (TempLen < Length) { - Block = (u32) ((u32)OffsetVar/BlockSize); - BlockLen = BlockSize - ((u32)OffsetVar % BlockSize); + Block = (u32)(OffsetVar/BlockSize); + BlockLen = BlockSize - (OffsetVar % BlockSize); + if (OffsetVar >= InstancePtr->Geometry.DeviceSize) { + Status = XST_FAILURE; + goto Out; + } /* * Check if the block is bad */ @@ -1690,10 +1694,6 @@ static s32 XNandPsu_CalculateLength(XNandPsu *InstancePtr, u64 Offset, */ TempLen += BlockLen; } - if (OffsetVar >= InstancePtr->Geometry.DeviceSize) { - Status = XST_FAILURE; - goto Out; - } OffsetVar += BlockLen; }