]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
scsi: mpt3sas: Fix a locking bug in an error path
authorBart Van Assche <bvanassche@acm.org>
Mon, 10 Feb 2025 20:39:36 +0000 (12:39 -0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 19 Feb 2025 02:36:08 +0000 (21:36 -0500)
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: c0767560b012 ("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>
drivers/scsi/mpt3sas/mpt3sas_base.c

index dc43cfa83088bb3a978e911680b12a8a74478358..212e3b86bb81785726799a223c2479192054a92b 100644 (file)
@@ -8018,7 +8018,7 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
 
        mutex_lock(&ioc->hostdiag_unlock_mutex);
        if (mpt3sas_base_unlock_and_get_host_diagnostic(ioc, &host_diagnostic))
-               goto out;
+               goto unlock;
 
        hcb_size = ioc->base_readl(&ioc->chip->HCBSize);
        drsprintk(ioc, ioc_info(ioc, "diag reset: issued\n"));
@@ -8038,7 +8038,7 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
                        ioc_info(ioc,
                            "Invalid host diagnostic register value\n");
                        _base_dump_reg_set(ioc);
-                       goto out;
+                       goto unlock;
                }
                if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
                        break;
@@ -8074,17 +8074,19 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc)
                ioc_err(ioc, "%s: failed going to ready state (ioc_state=0x%x)\n",
                        __func__, ioc_state);
                _base_dump_reg_set(ioc);
-               goto out;
+               goto fail;
        }
 
        pci_cfg_access_unlock(ioc->pdev);
        ioc_info(ioc, "diag reset: SUCCESS\n");
        return 0;
 
- out:
+unlock:
+       mutex_unlock(&ioc->hostdiag_unlock_mutex);
+
+fail:
        pci_cfg_access_unlock(ioc->pdev);
        ioc_err(ioc, "diag reset: FAILED\n");
-       mutex_unlock(&ioc->hostdiag_unlock_mutex);
        return -EFAULT;
 }