qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>, gleb@redhat.com
Subject: [Qemu-devel] [PATCH v2] ioport: Fix duplicated code
Date: Thu, 11 Nov 2010 12:03:26 -0200	[thread overview]
Message-ID: <20101111120326.22020026@doriath> (raw)

Functions register_ioport_read() and register_ioport_write() are almost
identical, the only difference is that they write to different arrays.

Introduce register_ioport_rw() to handle this difference and change both
functions to use it instead of duplicating code.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---

v2: Fix error messages and make register_ioport_rw() register both handlers
    at the same call

 ioport.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/ioport.c b/ioport.c
index ec3dc65..4560973 100644
--- a/ioport.c
+++ b/ioport.c
@@ -137,41 +137,40 @@ static int ioport_bsize(int size, int *bsize)
 }
 
 /* size is the word size in byte */
-int register_ioport_read(pio_addr_t start, int length, int size,
-                         IOPortReadFunc *func, void *opaque)
+static int register_ioport_rw(pio_addr_t start, int length, int size,
+                              IOPortReadFunc *read_func,
+                              IOPortWriteFunc *write_func, void *opaque)
 {
     int i, bsize;
 
     if (ioport_bsize(size, &bsize)) {
-        hw_error("register_ioport_read: invalid size");
+        hw_error("register_ioport_rw: invalid size");
         return -1;
     }
     for(i = start; i < start + length; i += size) {
-        ioport_read_table[bsize][i] = func;
+        if (read_func) {
+            ioport_read_table[bsize][i] = read_func;
+        }
+        if (write_func) {
+            ioport_write_table[bsize][i] = write_func;
+        }
         if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)
-            hw_error("register_ioport_read: invalid opaque");
+            hw_error("register_ioport_rw: invalid opaque");
         ioport_opaque[i] = opaque;
     }
     return 0;
 }
 
-/* size is the word size in byte */
+int register_ioport_read(pio_addr_t start, int length, int size,
+                         IOPortReadFunc *func, void *opaque)
+{
+    return register_ioport_rw(start, length, size, func, NULL, opaque);
+}
+
 int register_ioport_write(pio_addr_t start, int length, int size,
                           IOPortWriteFunc *func, void *opaque)
 {
-    int i, bsize;
-
-    if (ioport_bsize(size, &bsize)) {
-        hw_error("register_ioport_write: invalid size");
-        return -1;
-    }
-    for(i = start; i < start + length; i += size) {
-        ioport_write_table[bsize][i] = func;
-        if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)
-            hw_error("register_ioport_write: invalid opaque");
-        ioport_opaque[i] = opaque;
-    }
-    return 0;
+    return register_ioport_rw(start, length, size, NULL, func, opaque);
 }
 
 void isa_unassign_ioport(pio_addr_t start, int length)
-- 
1.7.3.2.164.g6f10c

             reply	other threads:[~2010-11-11 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-11 14:03 Luiz Capitulino [this message]
2010-11-20  1:50 ` [Qemu-devel] [PATCH v2] ioport: Fix duplicated code Anthony Liguori
2010-11-22 12:41   ` Luiz Capitulino

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=20101111120326.22020026@doriath \
    --to=lcapitulino@redhat.com \
    --cc=armbru@redhat.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@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).