]> git.proxmox.com Git - qemu.git/commitdiff
ioport: consolidate duplicated logic in register_ioport_{read, write}().
authorIsaku Yamahata <yamahata@valinux.co.jp>
Thu, 2 Jul 2009 10:32:08 +0000 (19:32 +0900)
committerAnthony Liguori <aliguori@us.ibm.com>
Thu, 9 Jul 2009 21:06:39 +0000 (16:06 -0500)
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
ioport.c

index 04bffc4cbc5be950fe7d077aef4d978a2fe01a27..01cfaf706172fbd5c5baadd1bb6b43dcc8434de7 100644 (file)
--- a/ioport.c
+++ b/ioport.c
@@ -121,19 +121,27 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
 #endif
 }
 
+static int ioport_bsize(int size, int *bsize)
+{
+    if (size == 1) {
+        *bsize = 0;
+    } else if (size == 2) {
+        *bsize = 1;
+    } else if (size == 4) {
+        *bsize = 2;
+    } else {
+        return -1;
+    }
+    return 0;
+}
+
 /* size is the word size in byte */
 int register_ioport_read(int start, int length, int size,
                          IOPortReadFunc *func, void *opaque)
 {
     int i, bsize;
 
-    if (size == 1) {
-        bsize = 0;
-    } else if (size == 2) {
-        bsize = 1;
-    } else if (size == 4) {
-        bsize = 2;
-    } else {
+    if (ioport_bsize(size, &bsize)) {
         hw_error("register_ioport_read: invalid size");
         return -1;
     }
@@ -152,13 +160,7 @@ int register_ioport_write(int start, int length, int size,
 {
     int i, bsize;
 
-    if (size == 1) {
-        bsize = 0;
-    } else if (size == 2) {
-        bsize = 1;
-    } else if (size == 4) {
-        bsize = 2;
-    } else {
+    if (ioport_bsize(size, &bsize)) {
         hw_error("register_ioport_write: invalid size");
         return -1;
     }