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>
This commit is contained in:
committed by
Linus Torvalds
parent
468fc53050
commit
cf446f0dba
@@ -194,52 +194,51 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
|
|||||||
ulong flags;
|
ulong flags;
|
||||||
|
|
||||||
n = (unsigned long) filp->private_data;
|
n = (unsigned long) filp->private_data;
|
||||||
switch (n) {
|
if (n != MINOR_ERR)
|
||||||
case MINOR_ERR:
|
return -EFAULT;
|
||||||
spin_lock_irqsave(&emsgs_lock, flags);
|
|
||||||
loop:
|
spin_lock_irqsave(&emsgs_lock, flags);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
em = emsgs + emsgs_head_idx;
|
em = emsgs + emsgs_head_idx;
|
||||||
if ((em->flags & EMFL_VALID) == 0) {
|
if ((em->flags & EMFL_VALID) != 0)
|
||||||
if (filp->f_flags & O_NDELAY) {
|
break;
|
||||||
spin_unlock_irqrestore(&emsgs_lock, flags);
|
if (filp->f_flags & O_NDELAY) {
|
||||||
return -EAGAIN;
|
|
||||||
}
|
|
||||||
nblocked_emsgs_readers++;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&emsgs_lock, flags);
|
|
||||||
|
|
||||||
n = down_interruptible(&emsgs_sema);
|
|
||||||
|
|
||||||
spin_lock_irqsave(&emsgs_lock, flags);
|
|
||||||
|
|
||||||
nblocked_emsgs_readers--;
|
|
||||||
|
|
||||||
if (n) {
|
|
||||||
spin_unlock_irqrestore(&emsgs_lock, flags);
|
|
||||||
return -ERESTARTSYS;
|
|
||||||
}
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
if (em->len > cnt) {
|
|
||||||
spin_unlock_irqrestore(&emsgs_lock, flags);
|
spin_unlock_irqrestore(&emsgs_lock, flags);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
mp = em->msg;
|
nblocked_emsgs_readers++;
|
||||||
len = em->len;
|
|
||||||
em->msg = NULL;
|
|
||||||
em->flags &= ~EMFL_VALID;
|
|
||||||
|
|
||||||
emsgs_head_idx++;
|
|
||||||
emsgs_head_idx %= ARRAY_SIZE(emsgs);
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&emsgs_lock, flags);
|
spin_unlock_irqrestore(&emsgs_lock, flags);
|
||||||
|
|
||||||
n = copy_to_user(buf, mp, len);
|
n = down_interruptible(&emsgs_sema);
|
||||||
kfree(mp);
|
|
||||||
return n == 0 ? len : -EFAULT;
|
spin_lock_irqsave(&emsgs_lock, flags);
|
||||||
default:
|
|
||||||
return -EFAULT;
|
nblocked_emsgs_readers--;
|
||||||
|
|
||||||
|
if (n) {
|
||||||
|
spin_unlock_irqrestore(&emsgs_lock, flags);
|
||||||
|
return -ERESTARTSYS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (em->len > cnt) {
|
||||||
|
spin_unlock_irqrestore(&emsgs_lock, flags);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
mp = em->msg;
|
||||||
|
len = em->len;
|
||||||
|
em->msg = NULL;
|
||||||
|
em->flags &= ~EMFL_VALID;
|
||||||
|
|
||||||
|
emsgs_head_idx++;
|
||||||
|
emsgs_head_idx %= ARRAY_SIZE(emsgs);
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&emsgs_lock, flags);
|
||||||
|
|
||||||
|
n = copy_to_user(buf, mp, len);
|
||||||
|
kfree(mp);
|
||||||
|
return n == 0 ? len : -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations aoe_fops = {
|
static const struct file_operations aoe_fops = {
|
||||||
|
Reference in New Issue
Block a user