qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yu <yu.liu@freescale.com>
To: agraf@suse.de
Cc: Liu Yu <yu.liu@freescale.com>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 2/2] ppc/e500_pci: Fix an array overflow issue
Date: Fri, 30 Sep 2011 11:52:50 +0800	[thread overview]
Message-ID: <1317354770-21531-2-git-send-email-yu.liu@freescale.com> (raw)
In-Reply-To: <1317354770-21531-1-git-send-email-yu.liu@freescale.com>

When access PPCE500_PCI_IW1 the previous index get overflow.
The patch fix the issue and update all to keep consistent style.

Signed-off-by: Liu Yu <yu.liu@freescale.com>
---
v2:
also apply idx for outbound to keep consistent style.

 hw/ppce500_pci.c |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c
index 0ece422..960a5d0 100644
--- a/hw/ppce500_pci.c
+++ b/hw/ppce500_pci.c
@@ -89,6 +89,7 @@ static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr)
     PPCE500PCIState *pci = opaque;
     unsigned long win;
     uint32_t value = 0;
+    int idx;
 
     win = addr & 0xfe0;
 
@@ -97,18 +98,19 @@ static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr)
     case PPCE500_PCI_OW2:
     case PPCE500_PCI_OW3:
     case PPCE500_PCI_OW4:
+        idx = (addr >> 5) & 0x7;
         switch (addr & 0xC) {
         case PCI_POTAR:
-            value = pci->pob[(addr >> 5) & 0x7].potar;
+            value = pci->pob[idx].potar;
             break;
         case PCI_POTEAR:
-            value = pci->pob[(addr >> 5) & 0x7].potear;
+            value = pci->pob[idx].potear;
             break;
         case PCI_POWBAR:
-            value = pci->pob[(addr >> 5) & 0x7].powbar;
+            value = pci->pob[idx].powbar;
             break;
         case PCI_POWAR:
-            value = pci->pob[(addr >> 5) & 0x7].powar;
+            value = pci->pob[idx].powar;
             break;
         default:
             break;
@@ -118,18 +120,19 @@ static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr)
     case PPCE500_PCI_IW3:
     case PPCE500_PCI_IW2:
     case PPCE500_PCI_IW1:
+        idx = ((addr >> 5) & 0x3) - 1;
         switch (addr & 0xC) {
         case PCI_PITAR:
-            value = pci->pib[(addr >> 5) & 0x3].pitar;
+            value = pci->pib[idx].pitar;
             break;
         case PCI_PIWBAR:
-            value = pci->pib[(addr >> 5) & 0x3].piwbar;
+            value = pci->pib[idx].piwbar;
             break;
         case PCI_PIWBEAR:
-            value = pci->pib[(addr >> 5) & 0x3].piwbear;
+            value = pci->pib[idx].piwbear;
             break;
         case PCI_PIWAR:
-            value = pci->pib[(addr >> 5) & 0x3].piwar;
+            value = pci->pib[idx].piwar;
             break;
         default:
             break;
@@ -160,6 +163,7 @@ static void pci_reg_write4(void *opaque, target_phys_addr_t addr,
 {
     PPCE500PCIState *pci = opaque;
     unsigned long win;
+    int idx;
 
     win = addr & 0xfe0;
 
@@ -171,18 +175,19 @@ static void pci_reg_write4(void *opaque, target_phys_addr_t addr,
     case PPCE500_PCI_OW2:
     case PPCE500_PCI_OW3:
     case PPCE500_PCI_OW4:
+        idx = (addr >> 5) & 0x7;
         switch (addr & 0xC) {
         case PCI_POTAR:
-            pci->pob[(addr >> 5) & 0x7].potar = value;
+            pci->pob[idx].potar = value;
             break;
         case PCI_POTEAR:
-            pci->pob[(addr >> 5) & 0x7].potear = value;
+            pci->pob[idx].potear = value;
             break;
         case PCI_POWBAR:
-            pci->pob[(addr >> 5) & 0x7].powbar = value;
+            pci->pob[idx].powbar = value;
             break;
         case PCI_POWAR:
-            pci->pob[(addr >> 5) & 0x7].powar = value;
+            pci->pob[idx].powar = value;
             break;
         default:
             break;
@@ -192,18 +197,19 @@ static void pci_reg_write4(void *opaque, target_phys_addr_t addr,
     case PPCE500_PCI_IW3:
     case PPCE500_PCI_IW2:
     case PPCE500_PCI_IW1:
+        idx = ((addr >> 5) & 0x3) - 1;
         switch (addr & 0xC) {
         case PCI_PITAR:
-            pci->pib[(addr >> 5) & 0x3].pitar = value;
+            pci->pib[idx].pitar = value;
             break;
         case PCI_PIWBAR:
-            pci->pib[(addr >> 5) & 0x3].piwbar = value;
+            pci->pib[idx].piwbar = value;
             break;
         case PCI_PIWBEAR:
-            pci->pib[(addr >> 5) & 0x3].piwbear = value;
+            pci->pib[idx].piwbear = value;
             break;
         case PCI_PIWAR:
-            pci->pib[(addr >> 5) & 0x3].piwar = value;
+            pci->pib[idx].piwar = value;
             break;
         default:
             break;
-- 
1.6.4

  reply	other threads:[~2011-09-30  5:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-30  3:52 [Qemu-devel] [PATCH 1/2] ppc/e500_pci: Fix code style Liu Yu
2011-09-30  3:52 ` Liu Yu [this message]
2011-10-07  6:55   ` [Qemu-devel] [PATCH v2 2/2] ppc/e500_pci: Fix an array overflow issue Alexander Graf
2011-10-01 13:05 ` [Qemu-devel] [Qemu-ppc] [PATCH 1/2] ppc/e500_pci: Fix code style Andreas Färber

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=1317354770-21531-2-git-send-email-yu.liu@freescale.com \
    --to=yu.liu@freescale.com \
    --cc=agraf@suse.de \
    --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).