Skip to content

Commit 0fd1814

Browse files
morbidrsamartinkpetersen
authored andcommitted
scsi: mpt3sas: Fix error returns in BRM_status_show
BRM_status_show() has several error branches, but none of them record the error in the error return. Also while at it remove the manual mutex_unlock() of the pci_access_mutex in case of an ongoing pci error recovery or host removal and jump to the cleanup label instead. Note: We can safely jump to out from here as io_unit_pg3 is initialized to NULL and if it hasn't been allocated, kfree() skips the NULL pointer. [mkp: compilation warning] Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Damien Le Moal <[email protected]> Acked-by: Sreekanth Reddy <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent cb551b8 commit 0fd1814

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/scsi/mpt3sas/mpt3sas_ctl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,15 +3149,14 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
31493149
}
31503150
/* pci_access_mutex lock acquired by sysfs show path */
31513151
mutex_lock(&ioc->pci_access_mutex);
3152-
if (ioc->pci_error_recovery || ioc->remove_host) {
3153-
mutex_unlock(&ioc->pci_access_mutex);
3154-
return 0;
3155-
}
3152+
if (ioc->pci_error_recovery || ioc->remove_host)
3153+
goto out;
31563154

31573155
/* allocate upto GPIOVal 36 entries */
31583156
sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
31593157
io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
31603158
if (!io_unit_pg3) {
3159+
rc = -ENOMEM;
31613160
ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
31623161
__func__, sz);
31633162
goto out;
@@ -3167,19 +3166,22 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
31673166
0) {
31683167
ioc_err(ioc, "%s: failed reading iounit_pg3\n",
31693168
__func__);
3169+
rc = -EINVAL;
31703170
goto out;
31713171
}
31723172

31733173
ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
31743174
if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
31753175
ioc_err(ioc, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n",
31763176
__func__, ioc_status);
3177+
rc = -EINVAL;
31773178
goto out;
31783179
}
31793180

31803181
if (io_unit_pg3->GPIOCount < 25) {
31813182
ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n",
31823183
__func__, io_unit_pg3->GPIOCount);
3184+
rc = -EINVAL;
31833185
goto out;
31843186
}
31853187

0 commit comments

Comments
 (0)