[SCSI] sg: fix races with ioctl(SG_IO)
authorTony Battersby <tonyb@cybernetics.com>
Tue, 20 Jan 2009 22:00:09 +0000 (17:00 -0500)
committerJames Bottomley <James.Bottomley@HansenPartnership.com>
Thu, 12 Mar 2009 17:58:05 +0000 (12:58 -0500)
commita2dd3b4cea335713b58996bb07b3abcde1175f47
tree3097816f8abd5fb57dda669d3e776c35f1455f43
parentc6517b7942fad663cc1cf3235cbe4207cf769332
[SCSI] sg: fix races with ioctl(SG_IO)

sg_io_owned needs to be set before the command is sent to the midlevel;
otherwise, a quickly-completing command may cause a different CPU
to see "srp->done == 1 && !srp->sg_io_owned", which would lead to
incorrect behavior.

Check srp->done and set srp->orphan while holding rq_list_lock to
prevent races with sg_rq_end_io().

There is no need to check sfp->closed from read/write/ioctl/poll/etc.
since the kernel guarantees that this won't happen.

The usefulness of sg_srp_done() was questionable before; now it is
definitely not needed.

Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
drivers/scsi/sg.c