[patch] fix locking in mpt2sas_ctl.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>

--- 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) {
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux