aboutsummaryrefslogtreecommitdiff
path: root/ioport.c
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2009-07-02 19:32:08 +0900
committerAnthony Liguori <aliguori@us.ibm.com>2009-07-09 16:06:39 -0500
commit23e0affdd293d0f6625a097911800b48b5428727 (patch)
treeaaa56f1750a2644ded56113aeb4cc99ee7f25794 /ioport.c
parentd56dd6cf031075bef985c831146691fdeec8af5c (diff)
ioport: consolidate duplicated logic in register_ioport_{read, write}().
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'ioport.c')
-rw-r--r--ioport.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/ioport.c b/ioport.c
index 04bffc4cbc..01cfaf7061 100644
--- 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;
}