qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, patches@linaro.org,
	Alexander Graf <agraf@suse.de>,
	qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] hw/ppc/ppc405_uc.c: Avoid integer overflows
Date: Wed, 22 Feb 2017 11:57:57 +1100	[thread overview]
Message-ID: <20170222005757.GB12577@umbus.fritz.box> (raw)
In-Reply-To: <1487684021-22713-1-git-send-email-peter.maydell@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2226 bytes --]

On Tue, Feb 21, 2017 at 01:33:41PM +0000, Peter Maydell wrote:
> When performing clock calculations, the ppc405_uc code
> has several places where it multiplies together two
> 32-bit variables and assigns the result to a 64-bit
> variable. This doesn't quite do what is intended because
> C will compute a 32-bit multiply result. Add casts to
> ensure we don't truncate the result.
> 
> (Spotted by Coverity, CID 1005504, 1005505.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Ouch.  Applied to ppc-for-2.9.

> ---
>  hw/ppc/ppc405_uc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
> index d6d3fc2..d5df94a 100644
> --- a/hw/ppc/ppc405_uc.c
> +++ b/hw/ppc/ppc405_uc.c
> @@ -1881,7 +1881,7 @@ static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc)
>          D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */
>          D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */
>          M = D0 * D1 * D2;
> -        VCO_out = cpc->sysclk * M;
> +        VCO_out = (uint64_t)cpc->sysclk * M;
>          if (VCO_out < 400000000 || VCO_out > 800000000) {
>              /* PLL cannot lock */
>              cpc->pllmr &= ~0x80000000;
> @@ -1892,7 +1892,7 @@ static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc)
>          /* Bypass PLL */
>      bypass_pll:
>          M = D0;
> -        PLL_out = cpc->sysclk * M;
> +        PLL_out = (uint64_t)cpc->sysclk * M;
>      }
>      CPU_clk = PLL_out;
>      if (cpc->cr1 & 0x00800000)
> @@ -2242,7 +2242,7 @@ static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc)
>  #ifdef DEBUG_CLOCKS_LL
>          printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D);
>  #endif
> -        VCO_out = cpc->sysclk * M * D;
> +        VCO_out = (uint64_t)cpc->sysclk * M * D;
>          if (VCO_out < 500000000UL || VCO_out > 1000000000UL) {
>              /* Error - unlock the PLL */
>              printf("VCO out of range %" PRIu64 "\n", VCO_out);

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

      parent reply	other threads:[~2017-02-22  1:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 13:33 [Qemu-devel] [PATCH] hw/ppc/ppc405_uc.c: Avoid integer overflows Peter Maydell
2017-02-21 22:20 ` Philippe Mathieu-Daudé
2017-02-22  0:57 ` David Gibson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170222005757.GB12577@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).