Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Eric.Moore@lsi.com
Cc: support@lsi.com, DL-MPTFusionLinux@lsi.com, linux-scsi@vger.kernel.org
Subject: [patch] fix locking in mpt2sas_ctl.c
Date: Wed, 22 Apr 2009 18:40:37 +0300 (EAT)	[thread overview]
Message-ID: <alpine.DEB.2.00.0904211827320.28180@bicker> (raw)

With state == NON_BLOCKING, we would either return -EAGAIN or double lock.

The other thing in patch is:
-                       return -ENOMEM;
+                       rc = -ENOMEM;
+                       goto out;

Going to out releases the ioc->ctl_cmds.mutex lock and sets 
ioc->ctl_cmds.status = MPT2_CMD_NOT_USED.

The patch is against 2.6.30-rc1.  Sorry if that is too old...
Found by smatch (http://repo.or.cz/w/smatch.git).  Compile tested only.  :/

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/drivers/scsi/mpt2sas/mpt2sas_ctl.c	2009-04-21 18:23:44.000000000 +0300
+++ devel/drivers/scsi/mpt2sas/mpt2sas_ctl.c	2009-04-21 18:38:41.000000000 +0300
@@ -550,7 +550,7 @@
 
 	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 && mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
 		return -ERESTARTSYS;
 
 	if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
@@ -1269,7 +1269,7 @@
 
 	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 && mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
 		return -ERESTARTSYS;
 
 	if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
@@ -1321,7 +1321,8 @@
 			    " for diag buffers, requested size(%d)\n",
 			    ioc->name, __func__, request_data_sz);
 			mpt2sas_base_free_smid(ioc, smid);
-			return -ENOMEM;
+			rc = -ENOMEM;
+			goto out;
 		}
 		ioc->diag_buffer[buffer_type] = request_data;
 		ioc->diag_buffer_sz[buffer_type] = request_data_sz;
@@ -1623,7 +1624,7 @@
 
 	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 && mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
 		return -ERESTARTSYS;
 
 	if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {
@@ -1787,7 +1788,7 @@
 	*/
 	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 && mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
 		return -ERESTARTSYS;
 
 	if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) {

                 reply	other threads:[~2009-04-22 15:40 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=alpine.DEB.2.00.0904211827320.28180@bicker \
    --to=error27@gmail.com \
    --cc=DL-MPTFusionLinux@lsi.com \
    --cc=Eric.Moore@lsi.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=support@lsi.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox