diff mbox

[6/8] hw/timer/exynos4210_mct: Avoid overflow in exynos4210_ltick_recalc_count

Message ID 1399574818-19349-7-git-send-email-peter.maydell@linaro.org
State New
Headers show

Commit Message

Peter Maydell May 8, 2014, 6:46 p.m. UTC
Add casts to avoid potentially overflowing the multiplications
of 32 bit quantities in exynos4210_ltick_recalc_count().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/timer/exynos4210_mct.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Peter Crosthwaite May 9, 2014, 11:49 p.m. UTC | #1
On Fri, May 9, 2014 at 4:46 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> Add casts to avoid potentially overflowing the multiplications
> of 32 bit quantities in exynos4210_ltick_recalc_count().
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  hw/timer/exynos4210_mct.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
> index 86f4fcd..69dbecd 100644
> --- a/hw/timer/exynos4210_mct.c
> +++ b/hw/timer/exynos4210_mct.c
> @@ -824,14 +824,14 @@ static void exynos4210_ltick_recalc_count(struct tick_timer *s)
>           */
>
>          if (s->last_tcnto) {
> -            to_count = s->last_tcnto * s->last_icnto;
> +            to_count = (uint64_t)s->last_tcnto * s->last_icnto;
>          } else {
>              to_count = s->last_icnto;
>          }
>      } else {
>          /* distance is passed, recalculate with tcnto * icnto */
>          if (s->icntb) {
> -            s->distance = s->tcntb * s->icntb;
> +            s->distance = (uint64_t)s->tcntb * s->icntb;
>          } else {
>              s->distance = s->tcntb;
>          }
> --
> 1.9.2
>
>
diff mbox

Patch

diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
index 86f4fcd..69dbecd 100644
--- a/hw/timer/exynos4210_mct.c
+++ b/hw/timer/exynos4210_mct.c
@@ -824,14 +824,14 @@  static void exynos4210_ltick_recalc_count(struct tick_timer *s)
          */
 
         if (s->last_tcnto) {
-            to_count = s->last_tcnto * s->last_icnto;
+            to_count = (uint64_t)s->last_tcnto * s->last_icnto;
         } else {
             to_count = s->last_icnto;
         }
     } else {
         /* distance is passed, recalculate with tcnto * icnto */
         if (s->icntb) {
-            s->distance = s->tcntb * s->icntb;
+            s->distance = (uint64_t)s->tcntb * s->icntb;
         } else {
             s->distance = s->tcntb;
         }