From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEzeR-0007jZ-Od for qemu-devel@nongnu.org; Sun, 16 Feb 2014 06:12:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WEzeN-0004Fy-Hw for qemu-devel@nongnu.org; Sun, 16 Feb 2014 06:12:47 -0500 From: Sebastian Huber Date: Sun, 16 Feb 2014 12:12:38 +0100 Message-Id: <1392549158-6009-1-git-send-email-sebastian.huber@embedded-brains.de> Subject: [Qemu-devel] [PATCH v2] hw/timer/grlib_gptimer: Avoid integer overflows List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, chouteau@adacore.com The GPTIMER uses 32-bit registers. Use a 64-bit operation to get the ptimer count, otherwise we end up with a count of 0 for GPTIMER counter values of 0xffffffff. Use the GPTIMER counter value for tracing to avoid an overflow of the 32-bit value passed to trace_grlib_gptimer_enable(). Reviewed-by: Fabien Chouteau Signed-off-by: Sebastian Huber --- hw/timer/grlib_gptimer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c index 74c16d6..7672d3a 100644 --- a/hw/timer/grlib_gptimer.c +++ b/hw/timer/grlib_gptimer.c @@ -106,9 +106,9 @@ static void grlib_gptimer_enable(GPTimer *timer) /* ptimer is triggered when the counter reach 0 but GPTimer is triggered at underflow. Set count + 1 to simulate the GPTimer behavior. */ - trace_grlib_gptimer_enable(timer->id, timer->counter + 1); + trace_grlib_gptimer_enable(timer->id, timer->counter); - ptimer_set_count(timer->ptimer, timer->counter + 1); + ptimer_set_count(timer->ptimer, (uint64_t)timer->counter + 1); ptimer_run(timer->ptimer, 1); } -- 1.8.1.4