Commit 23e0affdd293d0f6625a097911800b48b5428727

Authored by Isaku Yamahata
Committed by Anthony Liguori
1 parent d56dd6cf

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>
Showing 1 changed file with 16 additions and 14 deletions
ioport.c
@@ -121,19 +121,27 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) @@ -121,19 +121,27 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
121 #endif 121 #endif
122 } 122 }
123 123
  124 +static int ioport_bsize(int size, int *bsize)
  125 +{
  126 + if (size == 1) {
  127 + *bsize = 0;
  128 + } else if (size == 2) {
  129 + *bsize = 1;
  130 + } else if (size == 4) {
  131 + *bsize = 2;
  132 + } else {
  133 + return -1;
  134 + }
  135 + return 0;
  136 +}
  137 +
124 /* size is the word size in byte */ 138 /* size is the word size in byte */
125 int register_ioport_read(int start, int length, int size, 139 int register_ioport_read(int start, int length, int size,
126 IOPortReadFunc *func, void *opaque) 140 IOPortReadFunc *func, void *opaque)
127 { 141 {
128 int i, bsize; 142 int i, bsize;
129 143
130 - if (size == 1) {  
131 - bsize = 0;  
132 - } else if (size == 2) {  
133 - bsize = 1;  
134 - } else if (size == 4) {  
135 - bsize = 2;  
136 - } else { 144 + if (ioport_bsize(size, &bsize)) {
137 hw_error("register_ioport_read: invalid size"); 145 hw_error("register_ioport_read: invalid size");
138 return -1; 146 return -1;
139 } 147 }
@@ -152,13 +160,7 @@ int register_ioport_write(int start, int length, int size, @@ -152,13 +160,7 @@ int register_ioport_write(int start, int length, int size,
152 { 160 {
153 int i, bsize; 161 int i, bsize;
154 162
155 - if (size == 1) {  
156 - bsize = 0;  
157 - } else if (size == 2) {  
158 - bsize = 1;  
159 - } else if (size == 4) {  
160 - bsize = 2;  
161 - } else { 163 + if (ioport_bsize(size, &bsize)) {
162 hw_error("register_ioport_write: invalid size"); 164 hw_error("register_ioport_write: invalid size");
163 return -1; 165 return -1;
164 } 166 }