diff options
author | Edward O'Callaghan <eocallaghan@alterapraxis.com> | 2014-12-07 05:20:14 +1100 |
---|---|---|
committer | Edward O'Callaghan <eocallaghan@alterapraxis.com> | 2014-12-16 17:21:44 +0100 |
commit | cb0dd58b37b22f7731cd81da8024934040fafdc0 (patch) | |
tree | 2efaf202ec92218e1ed39f2345b4891fe4b53261 /src/vendorcode/amd/agesa/f10 | |
parent | 68402103eeae3e63a1ac358e6e7ebcc26d6ad249 (diff) |
amd/agesa/f*/Lib/amdlib.c: Integer overflow in loop construct
As is the case in commit:
3312ed7 amd/agesa/f1?/Lib/amdlib.c: Integer overflow in loop construct
The semantics of this loop relies on an integer overflow in Index >=0
that implies a return value of (UINT8)-1 which around wraps to 0xFF, or
VOLT_UNSUPPORTED.
Also fix an infinite loop.
Change-Id: Iced3eff3ae7b8935db3bdd6147372cf3b540883c
Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Reviewed-on: http://review.coreboot.org/7676
Reviewed-by: Bruce Griffith <Bruce.Griffith@se-eng.com>
Tested-by: build bot (Jenkins)
Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Diffstat (limited to 'src/vendorcode/amd/agesa/f10')
-rw-r--r-- | src/vendorcode/amd/agesa/f10/Lib/amdlib.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/vendorcode/amd/agesa/f10/Lib/amdlib.c b/src/vendorcode/amd/agesa/f10/Lib/amdlib.c index 83e6a009ab..860fb540f7 100644 --- a/src/vendorcode/amd/agesa/f10/Lib/amdlib.c +++ b/src/vendorcode/amd/agesa/f10/Lib/amdlib.c @@ -339,17 +339,25 @@ LibAmdBitScanForward ( } return (UINT8) Index; } + UINT8 LibAmdBitScanReverse ( IN UINT32 value ) { - UINT8 Index; - for (Index = 31; Index >= 0; Index--){ - if (value & (1 << Index)) return Index; - } - return 0xFF; + 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 */ } + VOID LibAmdMsrRead ( IN UINT32 MsrAddress, |