]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmArchTimerLib: Promotes 32bit value to prevent overflow
authorOlivier Martin <olivier.martin@arm.com>
Tue, 11 Nov 2014 00:52:46 +0000 (00:52 +0000)
committeroliviermartin <oliviermartin@Edk2>
Tue, 11 Nov 2014 00:52:46 +0000 (00:52 +0000)
Both MicroSeconds and PcdArmArchTimerFreqInHz are 32-bit values on
AArch32 so their multiplication produces 32-bit result that might
cause wrong calculation.

Example: With MicroSeconds = 200 us, PcdArmArchTimerFreqInHz = 24MHz.
200*24000000 = 0x1_1E1A_3000 => So 0x1E1A_3000 when the type is UINT32.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16329 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c

index 5d8e006cc99c0889aa23e2602b2ec758b28ec5f6..c0ab4a4433e431e806211495a532b07d22cb4e81 100644 (file)
@@ -85,7 +85,7 @@ MicroSecondDelay (
   // Calculate counter ticks that can represent requested delay:\r
   //  = MicroSeconds x TICKS_PER_MICRO_SEC\r
   //  = MicroSeconds x Frequency.10^-6\r
-  TimerTicks64 = (MicroSeconds * PcdGet32 (PcdArmArchTimerFreqInHz)) / 1000000U;\r
+  TimerTicks64 = ((UINT64)MicroSeconds * PcdGet32 (PcdArmArchTimerFreqInHz)) / 1000000U;\r
 \r
   // Read System Counter value\r
   SystemCounterVal = ArmGenericTimerGetSystemCount ();\r