From b9bc2571bebf05f9a295e80a66226064ef41b020 Mon Sep 17 00:00:00 2001 From: Ryan Salsamendi Date: Tue, 4 Jul 2017 13:35:06 -0700 Subject: northbridge/intel/haswell: Fix undefined behavior Fix undefined behavior found by clang's -Wshift-sign-overflow, grep, and source inspection. Left shifting an int where the right operand is >= the width of the type is undefined. Add UL suffix since it's safe for unsigned types. Change-Id: Id1ed2252ce3ed052730dd10b24c453c34c2ab4ff Signed-off-by: Ryan Salsamendi Reviewed-on: https://review.coreboot.org/20465 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- src/northbridge/intel/haswell/acpi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/northbridge/intel/haswell/acpi.c') diff --git a/src/northbridge/intel/haswell/acpi.c b/src/northbridge/intel/haswell/acpi.c index 8afef00baa..e032948e52 100644 --- a/src/northbridge/intel/haswell/acpi.c +++ b/src/northbridge/intel/haswell/acpi.c @@ -29,6 +29,7 @@ unsigned long acpi_fill_mcfg(unsigned long current) u32 pciexbar = 0; u32 pciexbar_reg; int max_buses; + u32 mask; dev = dev_find_slot(0, PCI_DEVFN(0, 0)); if (!dev) @@ -40,17 +41,20 @@ unsigned long acpi_fill_mcfg(unsigned long current) if (!(pciexbar_reg & (1 << 0))) return current; + mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28); switch ((pciexbar_reg >> 1) & 3) { case 0: // 256MB - pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); + pciexbar = pciexbar_reg & mask; max_buses = 256; break; case 1: // 128M - pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); + mask |= (1 << 27); + pciexbar = pciexbar_reg & mask; max_buses = 128; break; case 2: // 64M - pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); + mask |= (1 << 27) | (1 << 26); + pciexbar = pciexbar_reg & mask; max_buses = 64; break; default: // RSVD -- cgit v1.2.3