From: "Ed L. Cashin" <ecashin@coraid.com>
To: linux-kernel@vger.kernel.org
Cc: "Ed L. Cashin" <ecashin@coraid.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 05/13] eliminate goto and improve readability
Date: Thu, 20 Dec 2007 17:15:53 -0500 [thread overview]
Message-ID: <1198188961-25147-5-git-send-email-ecashin@coraid.com> (raw)
In-Reply-To: <1198188961-25147-1-git-send-email-ecashin@coraid.com>
Adam Richter suggested eliminating this goto.
Signed-off-by: Ed L. Cashin <ecashin@coraid.com>
---
drivers/block/aoe/aoechr.c | 69 +++++++++++++++++++++----------------------
1 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 03c7f4a..f112466 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -194,52 +194,51 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
ulong flags;
n = (unsigned long) filp->private_data;
- switch (n) {
- case MINOR_ERR:
- spin_lock_irqsave(&emsgs_lock, flags);
-loop:
- em = emsgs + emsgs_head_idx;
- if ((em->flags & EMFL_VALID) == 0) {
- if (filp->f_flags & O_NDELAY) {
- spin_unlock_irqrestore(&emsgs_lock, flags);
- return -EAGAIN;
- }
- nblocked_emsgs_readers++;
+ if (n != MINOR_ERR)
+ return -EFAULT;
+
+ spin_lock_irqsave(&emsgs_lock, flags);
+ for (;;) {
+ em = emsgs + emsgs_head_idx;
+ if ((em->flags & EMFL_VALID) != 0)
+ break;
+ if (filp->f_flags & O_NDELAY) {
spin_unlock_irqrestore(&emsgs_lock, flags);
+ return -EAGAIN;
+ }
+ nblocked_emsgs_readers++;
+
+ spin_unlock_irqrestore(&emsgs_lock, flags);
- n = down_interruptible(&emsgs_sema);
+ n = down_interruptible(&emsgs_sema);
- spin_lock_irqsave(&emsgs_lock, flags);
+ spin_lock_irqsave(&emsgs_lock, flags);
- nblocked_emsgs_readers--;
+ nblocked_emsgs_readers--;
- if (n) {
- spin_unlock_irqrestore(&emsgs_lock, flags);
- return -ERESTARTSYS;
- }
- goto loop;
- }
- if (em->len > cnt) {
+ if (n) {
spin_unlock_irqrestore(&emsgs_lock, flags);
- return -EAGAIN;
+ return -ERESTARTSYS;
}
- mp = em->msg;
- len = em->len;
- em->msg = NULL;
- em->flags &= ~EMFL_VALID;
+ }
+ 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);
+ 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);
- kfree(mp);
- return n == 0 ? len : -EFAULT;
- default:
- return -EFAULT;
- }
+ n = copy_to_user(buf, mp, len);
+ kfree(mp);
+ return n == 0 ? len : -EFAULT;
}
static const struct file_operations aoe_fops = {
--
1.5.3.4
next prev parent reply other threads:[~2007-12-20 22:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-20 22:15 [PATCH 01/13] bring driver version number to 47 Ed L. Cashin
2007-12-20 22:15 ` [PATCH 02/13] handle multiple network paths to AoE device Ed L. Cashin
2007-12-20 22:15 ` [PATCH 03/13] mac_addr: avoid 64-bit arch compiler warnings Ed L. Cashin
2007-12-20 22:15 ` [PATCH 04/13] clean up udev configuration example Ed L. Cashin
2007-12-20 22:15 ` Ed L. Cashin [this message]
2007-12-20 22:15 ` [PATCH 06/13] user can ask driver to forget previously detected devices Ed L. Cashin
2007-12-20 22:15 ` [PATCH 07/13] dynamically allocate a capped number of skbs when necessary Ed L. Cashin
2007-12-20 22:15 ` [PATCH 08/13] only install new AoE device once Ed L. Cashin
2007-12-20 22:15 ` [PATCH 09/13] remove race between use and initialization of locks Ed L. Cashin
2007-12-22 6:00 ` Andrew Morton
2007-12-26 19:28 ` Ed L. Cashin
2007-12-26 20:25 ` [PATCH] aoe: initialize locking structures before registering char devices Ed L. Cashin
2007-12-26 20:35 ` [PATCH] aoe: document the behavior of /dev/etherd/err Ed L. Cashin
2007-12-20 22:15 ` [PATCH 10/13] add module parameter for users who need more outstanding I/O Ed L. Cashin
2007-12-20 22:15 ` [PATCH 11/13] the aoeminor doesn't need a long format Ed L. Cashin
2007-12-20 22:16 ` [PATCH 12/13] make error messages more specific Ed L. Cashin
2007-12-20 22:16 ` [PATCH 13/13] update copyright date Ed L. Cashin
2007-12-22 6:03 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2007-12-07 17:47 [PATCH 01/13] bring driver version number to 47 Ed L. Cashin
2007-12-07 17:48 ` [PATCH 05/13] eliminate goto and improve readability Ed L. Cashin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1198188961-25147-5-git-send-email-ecashin@coraid.com \
--to=ecashin@coraid.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).