[SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Tue, 28 Aug 2012 14:38:02 +0000 (18:38 +0400)
committerJames Bottomley <JBottomley@Parallels.com>
Mon, 24 Sep 2012 08:10:59 +0000 (12:10 +0400)
If state is NON_BLOCKING and mutex_trylock is succeed,
the control flow goes to mutex_lock_interruptible() that is a deadlock.

[jejb: fixed coding style problems]
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: "Sreekanth Reddy" <sreekanth.reddy@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/mpt2sas/mpt2sas_ctl.c

index 64254416a178899677d1470c36bb8efee06c72ce..08685c4cf231b99c89c9eb3b91f1dcbc4641b508 100644 (file)
@@ -2181,10 +2181,12 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
                return -EAGAIN;
 
        state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
-       if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
-               return -EAGAIN;
-       else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
+       if (state == NON_BLOCKING) {
+               if (!mutex_trylock(&ioc->ctl_cmds.mutex))
+                       return -EAGAIN;
+       } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
                return -ERESTARTSYS;
+       }
 
        switch (cmd) {
        case MPT2IOCINFO: