Patrick Georgi (pgeorgi@google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17834
-gerrit
commit 36639926f298325031e71ef8c73a22a336f638b7 Author: Patrick Georgi pgeorgi@chromium.org Date: Tue Dec 13 15:42:58 2016 +0100
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 --- src/vendorcode/amd/pi/Lib/amdlib.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/vendorcode/amd/pi/Lib/amdlib.c b/src/vendorcode/amd/pi/Lib/amdlib.c index 4c8a56d..03ca207 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