summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2020-04-15 20:54:14 +0800
committerPatrick Georgi <pgeorgi@google.com>2020-04-20 06:20:50 +0000
commit85ecdb1471dd695997166f447f786ed500d091b9 (patch)
tree19955f93d8ee0872a57b389c7bf1cff11d5bd518 /src/include
parent38e386f2d0255fdc424b0efe73585ea4ab9e8b1b (diff)
mmio: Fix failure in bit field macro when accessing >30 bits
For bit fields with 31 bits (e.g: DEFINE_BITFIELD(MYREG, 30, 0) ), the calculation of mask value will go overflow: "error: integer overflow in expression '-2147483648 - 1' of type 'int' results in '2147483647'". And for bit fields with 32 bits (e.g: DEFINE_BITFIELD(MYREG, 31, 0) ), the error will be: "error: left shift count >= width of type [-Werror=shift-count-overflow]" To fix these issues, the bit field macros should always use unsigned integers, and use 64bit integer when creating mask value. Change-Id: Ie3cddf9df60b83de4e21243bfde6b79729fb06ef Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/40404 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/device/mmio.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/include/device/mmio.h b/src/include/device/mmio.h
index b4f2ab639f..a725a62953 100644
--- a/src/include/device/mmio.h
+++ b/src/include/device/mmio.h
@@ -131,10 +131,10 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
#define DEFINE_BIT(name, bit) DEFINE_BITFIELD(name, bit, bit)
#define _BF_MASK(name, value) \
- (((1 << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
+ ((u32)((1ULL << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
#define _BF_VALUE(name, value) \
- ((value) << name##_BITFIELD_SHIFT)
+ (((u32)(value) << name##_BITFIELD_SHIFT) & _BF_MASK(name, 0))
#define _BF_APPLY1(op, name, value, ...) (op(name, value))
#define _BF_APPLY2(op, name, value, ...) ((op(name, value)) | \