summaryrefslogtreecommitdiffstats
path: root/src/vendorcode
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@chromium.org>2016-12-13 15:42:58 +0100
committerPatrick Georgi <pgeorgi@google.com>2016-12-14 15:58:15 +0100
commitcf3b306cafdb76493ff605c5dd05bbd602293147 (patch)
treef454fdcc053701d37824af253e270e2b62764545 /src/vendorcode
parenta1df15efc82a0ec03bd7353f5f51a2f288c01685 (diff)
downloadcoreboot-cf3b306cafdb76493ff605c5dd05bbd602293147.tar.gz
coreboot-cf3b306cafdb76493ff605c5dd05bbd602293147.tar.bz2
coreboot-cf3b306cafdb76493ff605c5dd05bbd602293147.zip
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)
Diffstat (limited to 'src/vendorcode')
-rw-r--r--src/vendorcode/amd/pi/Lib/amdlib.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/vendorcode/amd/pi/Lib/amdlib.c b/src/vendorcode/amd/pi/Lib/amdlib.c
index 4c8a56dba80d..03ca20798797 100644
--- a/src/vendorcode/amd/pi/Lib/amdlib.c
+++ b/src/vendorcode/amd/pi/Lib/amdlib.c
@@ -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