From 6476cb3bbd0ee98395d225163641da372a1772b0 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Thu, 13 Mar 2014 17:55:07 +0100 Subject: [PATCH] mmio: fix type inaccuracy in bitset reads We must ensure that the type in use fits the shift value that gets applied while combining the bitset sub-values. ref #1095 --- base/include/util/mmio.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/base/include/util/mmio.h b/base/include/util/mmio.h index 4bb2d7fdee..332884e93a 100644 --- a/base/include/util/mmio.h +++ b/base/include/util/mmio.h @@ -520,8 +520,11 @@ namespace Genode { typedef typename T::Bitset_2_base::Bits_0 Bits_0; typedef typename T::Bitset_2_base::Bits_1 Bits_1; - return read() | - (read() << Bits_0::BITFIELD_WIDTH); + typedef typename T::Bitset_2_base::access_t access_t; + enum { V1_SHIFT = Bits_0::BITFIELD_WIDTH }; + access_t const v0 = read(); + access_t const v1 = read(); + return v0 | (v1 << V1_SHIFT); } /** @@ -547,9 +550,15 @@ namespace Genode typedef typename T::Bitset_3_base::Bits_0 Bits_0; typedef typename T::Bitset_3_base::Bits_1 Bits_1; typedef typename T::Bitset_3_base::Bits_2 Bits_2; - return read >() | - (read() << (Bits_0::BITFIELD_WIDTH + - Bits_1::BITFIELD_WIDTH)); + typedef typename T::Bitset_3_base::access_t access_t; + enum { + BITS_0_WIDTH = Bits_0::BITFIELD_WIDTH, + BITS_1_WIDTH = Bits_1::BITFIELD_WIDTH, + V1_SHIFT = BITS_0_WIDTH + BITS_1_WIDTH, + }; + access_t const v0 = read >(); + access_t const v1 = read(); + return v0 | (v1 << V1_SHIFT); } /**