From 85ecdb1471dd695997166f447f786ed500d091b9 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 15 Apr 2020 20:54:14 +0800 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/40404 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/include/device/mmio.h | 4 ++-- 1 file 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)) | \ -- cgit v1.2.3