Commit 3f0c6aba authored by Jörn Engel's avatar Jörn Engel Committed by James Bottomley

[SCSI] sg: use wait_event_interruptible()

Afaics the use of __wait_event_interruptible() as opposed to
wait_event_interruptible() is purely historic.  So let's follow the rest
of the kernel and check the condition before prepare_to_wait() - and
also make the code a bit nicer.
Signed-off-by: default avatarJoern Engel <joern@logfs.org>
Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
Signed-off-by: default avatarJames Bottomley <JBottomley@Parallels.com>
parent 794c10fa
...@@ -268,9 +268,8 @@ sg_open(struct inode *inode, struct file *filp) ...@@ -268,9 +268,8 @@ sg_open(struct inode *inode, struct file *filp)
retval = -EBUSY; retval = -EBUSY;
goto error_out; goto error_out;
} }
res = 0; res = wait_event_interruptible(sdp->o_excl_wait,
__wait_event_interruptible(sdp->o_excl_wait, ((!list_empty(&sdp->sfds) || sdp->exclude) ? 0 : (sdp->exclude = 1)));
((!list_empty(&sdp->sfds) || sdp->exclude) ? 0 : (sdp->exclude = 1)), res);
if (res) { if (res) {
retval = res; /* -ERESTARTSYS because signal hit process */ retval = res; /* -ERESTARTSYS because signal hit process */
goto error_out; goto error_out;
...@@ -280,9 +279,7 @@ sg_open(struct inode *inode, struct file *filp) ...@@ -280,9 +279,7 @@ sg_open(struct inode *inode, struct file *filp)
retval = -EBUSY; retval = -EBUSY;
goto error_out; goto error_out;
} }
res = 0; res = wait_event_interruptible(sdp->o_excl_wait, !sdp->exclude);
__wait_event_interruptible(sdp->o_excl_wait, (!sdp->exclude),
res);
if (res) { if (res) {
retval = res; /* -ERESTARTSYS because signal hit process */ retval = res; /* -ERESTARTSYS because signal hit process */
goto error_out; goto error_out;
...@@ -398,10 +395,9 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) ...@@ -398,10 +395,9 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
retval = -EAGAIN; retval = -EAGAIN;
goto free_old_hdr; goto free_old_hdr;
} }
retval = 0; /* following macro beats race condition */ retval = wait_event_interruptible(sfp->read_wait,
__wait_event_interruptible(sfp->read_wait,
(sdp->detached || (sdp->detached ||
(srp = sg_get_rq_mark(sfp, req_pack_id))), retval); (srp = sg_get_rq_mark(sfp, req_pack_id))));
if (sdp->detached) { if (sdp->detached) {
retval = -ENODEV; retval = -ENODEV;
goto free_old_hdr; goto free_old_hdr;
...@@ -797,9 +793,8 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) ...@@ -797,9 +793,8 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1, read_only, 1, &srp); 1, read_only, 1, &srp);
if (result < 0) if (result < 0)
return result; return result;
result = 0; /* following macro to beat race condition */ result = wait_event_interruptible(sfp->read_wait,
__wait_event_interruptible(sfp->read_wait, (srp->done || sdp->detached));
(srp->done || sdp->detached), result);
if (sdp->detached) if (sdp->detached)
return -ENODEV; return -ENODEV;
write_lock_irq(&sfp->rq_list_lock); write_lock_irq(&sfp->rq_list_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment