From: vaughan <vaughan.cao@oracle.com>
To: Xitao Cao <xitao.cao@gmail.com>
Cc: vaughan.cao@oracle.com, linux-kernel@vger.kernel.org
Subject: [PATCH] [SCSI] sg: atomize check and set sdp->exclude
Date: Wed, 5 Jun 2013 02:13:55 -0700 (PDT) [thread overview]
Message-ID: <51AF0153.2050704@oracle.com> (raw)
Check and set sdp->exclude should be atomic when set in sg_open().
Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
---
drivers/scsi/sg.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 25b5455..0ede08f 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -245,6 +245,21 @@ static int set_exclude(Sg_device *sdp, char val)
return val;
}
+/* Check if we can set exclude and then set, return 1 if success */
+static int try_set_exclude(Sg_device *sdp)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&sg_open_exclusive_lock, flags);
+ if (sdp->exclude) {
+ spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
+ return 0;
+ }
+ sdp->exclude = 1;
+ spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
+ return 1;
+}
+
static int sfds_list_empty(Sg_device *sdp)
{
unsigned long flags;
@@ -303,7 +318,7 @@ sg_open(struct inode *inode, struct file *filp)
goto error_out;
}
res = wait_event_interruptible(sdp->o_excl_wait,
- ((!sfds_list_empty(sdp) || get_exclude(sdp)) ? 0
: set_exclude(sdp, 1)));
+ ((!sfds_list_empty(sdp) || get_exclude(sdp)) ? 0 :
try_set_exclude(sdp)));
if (res) {
retval = res; /* -ERESTARTSYS because signal hit process */
goto error_out;
--
1.7.11.7
reply other threads:[~2013-06-05 9:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=51AF0153.2050704@oracle.com \
--to=vaughan.cao@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xitao.cao@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.