summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2009-10-30 21:21:04 +0900
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-09 08:43:07 -0600
commit5029fe12dccbe261d5bd5bc840110ae48aa112c9 (patch)
tree8d737f9433cbff89948b0a9f33386a8420dba666
parent0392a017ae9b44dd5c29bf7769a96fd6806a3551 (diff)
downloadfocaccia-qemu-5029fe12dccbe261d5bd5bc840110ae48aa112c9.tar.gz
focaccia-qemu-5029fe12dccbe261d5bd5bc840110ae48aa112c9.zip
pci: clean up of pci_default_read_config.
This patch cleans up pci_default_read_config() removing
ugly length and range check.

Suggested by "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/pci.c26
1 files changed, 5 insertions, 21 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 91acb85e2d..6b89177aab 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -558,27 +558,11 @@ static void pci_update_mappings(PCIDevice *d)
 uint32_t pci_default_read_config(PCIDevice *d,
                                  uint32_t address, int len)
 {
-    uint32_t val;
-
-    switch(len) {
-    default:
-    case 4:
-	if (address <= 0xfc) {
-            val = pci_get_long(d->config + address);
-	    break;
-	}
-	/* fall through */
-    case 2:
-        if (address <= 0xfe) {
-            val = pci_get_word(d->config + address);
-	    break;
-	}
-	/* fall through */
-    case 1:
-        val = pci_get_byte(d->config + address);
-        break;
-    }
-    return val;
+    uint32_t val = 0;
+    assert(len == 1 || len == 2 || len == 4);
+    len = MIN(len, PCI_CONFIG_SPACE_SIZE - address);
+    memcpy(&val, d->config + address, len);
+    return le32_to_cpu(val);
 }
 
 void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)