linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state
@ 2012-08-28 14:38 Alexey Khoroshilov
  2012-08-29 10:18 ` Reddy, Sreekanth
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Khoroshilov @ 2012-08-28 14:38 UTC (permalink / raw)
  To: James E.J. Bottomley
  Cc: Alexey Khoroshilov, linux-scsi, Nagalakshmi Nandigama,
	Sreekanth.Reddy, linux-kernel, ldv-project

If state is NON_BLOCKING and mutex_trylock is succeed,
the control flow goes to mutex_lock_interruptible() that is a deadlock.

The previous version of the patch becomes obsolete after 
code movement in commit 913809f6.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/scsi/mpt2sas/mpt2sas_ctl.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 49bdd2d..d29ea56 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -2181,8 +2181,10 @@ _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;
+	if (state == NON_BLOCKING) {
+		if (!mutex_trylock(&ioc->ctl_cmds.mutex))
+			return -EAGAIN;
+	}
 	else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
 		return -ERESTARTSYS;
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH v2] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state
  2012-08-28 14:38 [PATCH v2] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state Alexey Khoroshilov
@ 2012-08-29 10:18 ` Reddy, Sreekanth
  0 siblings, 0 replies; 2+ messages in thread
From: Reddy, Sreekanth @ 2012-08-29 10:18 UTC (permalink / raw)
  To: Alexey Khoroshilov, James E.J. Bottomley
  Cc: linux-scsi, Nandigama, Nagalakshmi, linux-kernel, ldv-project

James,

This patch seem to be fine. Please consider this patch as Acked-by: "Sreekanth Reddy" <sreekanth.reddy@lsi.com>

Regards,
Sreekanth.

> -----Original Message-----
> From: Alexey Khoroshilov [mailto:khoroshilov@ispras.ru]
> Sent: Tuesday, August 28, 2012 8:08 PM
> To: James E.J. Bottomley
> Cc: Alexey Khoroshilov; linux-scsi@vger.kernel.org; Nandigama,
> Nagalakshmi; Reddy, Sreekanth; linux-kernel@vger.kernel.org; ldv-
> project@ispras.ru
> Subject: [PATCH v2] [SCSI] mpt2sas: fix double mutex lock in
> NON_BLOCKING state
> 
> If state is NON_BLOCKING and mutex_trylock is succeed,
> the control flow goes to mutex_lock_interruptible() that is a deadlock.
> 
> The previous version of the patch becomes obsolete after
> code movement in commit 913809f6.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  drivers/scsi/mpt2sas/mpt2sas_ctl.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
> b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
> index 49bdd2d..d29ea56 100644
> --- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
> +++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
> @@ -2181,8 +2181,10 @@ _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;
> +	if (state == NON_BLOCKING) {
> +		if (!mutex_trylock(&ioc->ctl_cmds.mutex))
> +			return -EAGAIN;
> +	}
>  	else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
>  		return -ERESTARTSYS;
> 
> --
> 1.7.9.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-29 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-28 14:38 [PATCH v2] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state Alexey Khoroshilov
2012-08-29 10:18 ` Reddy, Sreekanth

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).