Skip to content

Commit cf446f0

Browse files
ecashinLinus Torvalds
authored andcommitted
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>
1 parent 468fc53 commit cf446f0

1 file changed

Lines changed: 34 additions & 35 deletions

File tree

‎drivers/block/aoe/aoechr.c‎

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -194,52 +194,51 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
194194
ulong flags;
195195

196196
n = (unsigned long) filp->private_data;
197-
switch (n) {
198-
case MINOR_ERR:
199-
spin_lock_irqsave(&emsgs_lock, flags);
200-
loop:
201-
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++;
197+
if (n != MINOR_ERR)
198+
return -EFAULT;
199+
200+
spin_lock_irqsave(&emsgs_lock, flags);
208201

202+
for (;;) {
203+
em = emsgs + emsgs_head_idx;
204+
if ((em->flags & EMFL_VALID) != 0)
205+
break;
206+
if (filp->f_flags & O_NDELAY) {
209207
spin_unlock_irqrestore(&emsgs_lock, flags);
208+
return -EAGAIN;
209+
}
210+
nblocked_emsgs_readers++;
211+
212+
spin_unlock_irqrestore(&emsgs_lock, flags);
210213

211-
n = down_interruptible(&emsgs_sema);
214+
n = down_interruptible(&emsgs_sema);
212215

213-
spin_lock_irqsave(&emsgs_lock, flags);
216+
spin_lock_irqsave(&emsgs_lock, flags);
214217

215-
nblocked_emsgs_readers--;
218+
nblocked_emsgs_readers--;
216219

217-
if (n) {
218-
spin_unlock_irqrestore(&emsgs_lock, flags);
219-
return -ERESTARTSYS;
220-
}
221-
goto loop;
222-
}
223-
if (em->len > cnt) {
220+
if (n) {
224221
spin_unlock_irqrestore(&emsgs_lock, flags);
225-
return -EAGAIN;
222+
return -ERESTARTSYS;
226223
}
227-
mp = em->msg;
228-
len = em->len;
229-
em->msg = NULL;
230-
em->flags &= ~EMFL_VALID;
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;
231233

232-
emsgs_head_idx++;
233-
emsgs_head_idx %= ARRAY_SIZE(emsgs);
234+
emsgs_head_idx++;
235+
emsgs_head_idx %= ARRAY_SIZE(emsgs);
234236

235-
spin_unlock_irqrestore(&emsgs_lock, flags);
237+
spin_unlock_irqrestore(&emsgs_lock, flags);
236238

237-
n = copy_to_user(buf, mp, len);
238-
kfree(mp);
239-
return n == 0 ? len : -EFAULT;
240-
default:
241-
return -EFAULT;
242-
}
239+
n = copy_to_user(buf, mp, len);
240+
kfree(mp);
241+
return n == 0 ? len : -EFAULT;
243242
}
244243

245244
static const struct file_operations aoe_fops = {

0 commit comments

Comments
 (0)