fix locking in mpt2sas_ctl.c
PATCH 1/1 fix locking in mpt2sas_ctl.c
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 <[email protected]>
drivers/scsi/mpt2sas/mpt2sas_ctl.c +6 -5
@@ -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 ) {