Skip to content

Commit 2ac5da3

Browse files
Chandrakanth Patilroot
authored andcommitted
scsi: mpt3sas: Fix a locking bug in an error path
JIRA: https://issues.redhat.com/browse/RHEL-81907 Call mutex_unlock(&ioc->hostdiag_unlock_mutex) once from error paths instead of twice. This patch fixes the following Clang -Wthread-safety errors: drivers/scsi/mpt3sas/mpt3sas_base.c:8085:2: error: mutex 'ioc->hostdiag_unlock_mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis] 8085 | pci_cfg_access_unlock(ioc->pdev); | ^ drivers/scsi/mpt3sas/mpt3sas_base.c:8019:2: note: mutex acquired here 8019 | mutex_lock(&ioc->hostdiag_unlock_mutex); | ^ ./include/linux/mutex.h:171:26: note: expanded from macro 'mutex_lock' 171 | #define mutex_lock(lock) mutex_lock_nested(lock, 0) | ^ drivers/scsi/mpt3sas/mpt3sas_base.c:8085:2: error: mutex 'ioc->hostdiag_unlock_mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis] 8085 | pci_cfg_access_unlock(ioc->pdev); | ^ drivers/scsi/mpt3sas/mpt3sas_base.c:8019:2: note: mutex acquired here 8019 | mutex_lock(&ioc->hostdiag_unlock_mutex); | ^ ./include/linux/mutex.h:171:26: note: expanded from macro 'mutex_lock' 171 | #define mutex_lock(lock) mutex_lock_nested(lock, 0) | ^ drivers/scsi/mpt3sas/mpt3sas_base.c:8087:2: error: releasing mutex 'ioc->hostdiag_unlock_mutex' that was not held [-Werror,-Wthread-safety-analysis] 8087 | mutex_unlock(&ioc->hostdiag_unlock_mutex); | ^ Cc: Ranjan Kumar <ranjan.kumar@broadcom.com> Fixes: c076756 ("scsi: mpt3sas: Reload SBR without rebooting HBA") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20250210203936.2946494-3-bvanassche@acm.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> (cherry picked from commit 38afcf0) Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
1 parent 8949d3b commit 2ac5da3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/scsi/mpt3sas/mpt3sas_base.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,7 +8018,7 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
80188018

80198019
mutex_lock(&ioc->hostdiag_unlock_mutex);
80208020
if (mpt3sas_base_unlock_and_get_host_diagnostic(ioc, &host_diagnostic))
8021-
goto out;
8021+
goto unlock;
80228022

80238023
hcb_size = ioc->base_readl(&ioc->chip->HCBSize);
80248024
drsprintk(ioc, ioc_info(ioc, "diag reset: issued\n"));
@@ -8038,7 +8038,7 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
80388038
ioc_info(ioc,
80398039
"Invalid host diagnostic register value\n");
80408040
_base_dump_reg_set(ioc);
8041-
goto out;
8041+
goto unlock;
80428042
}
80438043
if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
80448044
break;
@@ -8074,17 +8074,19 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
80748074
ioc_err(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n",
80758075
__func__, ioc_state);
80768076
_base_dump_reg_set(ioc);
8077-
goto out;
8077+
goto fail;
80788078
}
80798079

80808080
pci_cfg_access_unlock(ioc->pdev);
80818081
ioc_info(ioc, "diag reset: SUCCESS\n");
80828082
return 0;
80838083

8084-
out:
8084+
unlock:
8085+
mutex_unlock(&ioc->hostdiag_unlock_mutex);
8086+
8087+
fail:
80858088
pci_cfg_access_unlock(ioc->pdev);
80868089
ioc_err(ioc, "diag reset: FAILED\n");
8087-
mutex_unlock(&ioc->hostdiag_unlock_mutex);
80888090
return -EFAULT;
80898091
}
80908092

0 commit comments

Comments
 (0)