vendorcode/amd: Fix non-terminating loop

Code is copied from agesa/common's amdlib.c.
Things can probably be deduplicated.

Change-Id: I9c8adab5db7e9fd41aecc522136dfa705c1e2ee6
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Found-by: Coverity Scan #1229662
Reviewed-on: https://review.coreboot.org/17834
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Martin Roth <martinroth@google.com>
Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Patrick Georgi 2016-12-13 15:42:58 +01:00 committed by Patrick Georgi
parent a1df15efc8
commit cf3b306caf
1 changed files with 11 additions and 5 deletions

View File

@ -381,11 +381,17 @@ LibAmdBitScanReverse (
IN UINT32 value
)
{
UINTN Index;
for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break;
}
return (UINT8) Index;
uint8_t bit = 31;
do {
if (value & (1 << 31))
return bit;
value <<= 1;
bit--;
} while (value != 0);
return 0xFF; /* Error code indicating no bit found */
}
AMDLIB_OPTIMIZE