Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

aoe: eliminate goto and improve readability

Adam Richter suggested eliminating this goto.

Signed-off-by: Ed L. Cashin <ecashin@coraid.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ed L. Cashin and committed by
Linus Torvalds
cf446f0d 468fc530

+37 -38
+37 -38
drivers/block/aoe/aoechr.c
··· 194 194 ulong flags; 195 195 196 196 n = (unsigned long) filp->private_data; 197 - switch (n) { 198 - case MINOR_ERR: 199 - spin_lock_irqsave(&emsgs_lock, flags); 200 - loop: 197 + if (n != MINOR_ERR) 198 + return -EFAULT; 199 + 200 + spin_lock_irqsave(&emsgs_lock, flags); 201 + 202 + for (;;) { 201 203 em = emsgs + emsgs_head_idx; 202 - if ((em->flags & EMFL_VALID) == 0) { 203 - if (filp->f_flags & O_NDELAY) { 204 - spin_unlock_irqrestore(&emsgs_lock, flags); 205 - return -EAGAIN; 206 - } 207 - nblocked_emsgs_readers++; 208 - 209 - spin_unlock_irqrestore(&emsgs_lock, flags); 210 - 211 - n = down_interruptible(&emsgs_sema); 212 - 213 - spin_lock_irqsave(&emsgs_lock, flags); 214 - 215 - nblocked_emsgs_readers--; 216 - 217 - if (n) { 218 - spin_unlock_irqrestore(&emsgs_lock, flags); 219 - return -ERESTARTSYS; 220 - } 221 - goto loop; 222 - } 223 - if (em->len > cnt) { 204 + if ((em->flags & EMFL_VALID) != 0) 205 + break; 206 + if (filp->f_flags & O_NDELAY) { 224 207 spin_unlock_irqrestore(&emsgs_lock, flags); 225 208 return -EAGAIN; 226 209 } 227 - mp = em->msg; 228 - len = em->len; 229 - em->msg = NULL; 230 - em->flags &= ~EMFL_VALID; 231 - 232 - emsgs_head_idx++; 233 - emsgs_head_idx %= ARRAY_SIZE(emsgs); 210 + nblocked_emsgs_readers++; 234 211 235 212 spin_unlock_irqrestore(&emsgs_lock, flags); 236 213 237 - n = copy_to_user(buf, mp, len); 238 - kfree(mp); 239 - return n == 0 ? len : -EFAULT; 240 - default: 241 - return -EFAULT; 214 + n = down_interruptible(&emsgs_sema); 215 + 216 + spin_lock_irqsave(&emsgs_lock, flags); 217 + 218 + nblocked_emsgs_readers--; 219 + 220 + if (n) { 221 + spin_unlock_irqrestore(&emsgs_lock, flags); 222 + return -ERESTARTSYS; 223 + } 242 224 } 225 + if (em->len > cnt) { 226 + spin_unlock_irqrestore(&emsgs_lock, flags); 227 + return -EAGAIN; 228 + } 229 + mp = em->msg; 230 + len = em->len; 231 + em->msg = NULL; 232 + em->flags &= ~EMFL_VALID; 233 + 234 + emsgs_head_idx++; 235 + emsgs_head_idx %= ARRAY_SIZE(emsgs); 236 + 237 + spin_unlock_irqrestore(&emsgs_lock, flags); 238 + 239 + n = copy_to_user(buf, mp, len); 240 + kfree(mp); 241 + return n == 0 ? len : -EFAULT; 243 242 } 244 243 245 244 static const struct file_operations aoe_fops = {