[PATCH v3 04/11] scsi: mpt3sas: Fix pcie_device leak in _scsih_ublock_io_device_wait()
From: Jeff Layton
Date: Wed Nov 18 2026 - 18:10:31 EST
_scsih_ublock_io_device_wait() gets the pcie_device on each pass of its
TEST UNIT READY retry loop. But it puts the pcie_device only at the
bottom of the loop. The DEVICE_RETRY/START_UNIT/STOP_UNIT/RETRY_UA
branch ends in a continue, which skips the put. Thus each retry of an
NVMe device leaks a reference, and the driver can never free the
_pcie_device.
The function needs the pcie_device only for the reset timeout and the
reset method. Put the pcie_device immediately after the function reads
these values.
Fixes: aee682fad6cd ("scsi: mpt3sas: Improve device discovery and readiness handling for slow devices")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 2d98fcb8e135..45419f0ebedc 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4220,6 +4220,8 @@ _scsih_ublock_io_device_wait(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
tr_timeout = pcie_device->reset_timeout;
tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
}
+ if (pcie_device)
+ pcie_device_put(pcie_device);
rc = _scsih_wait_for_device_to_become_ready(ioc,
sas_target->handle, 0, (sas_target->flags &
MPT_TARGET_FLAGS_RAID_COMPONENT), sdev->lun, tr_timeout, tr_method);
@@ -4241,8 +4243,6 @@ _scsih_ublock_io_device_wait(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
}
continue;
}
- if (pcie_device)
- pcie_device_put(pcie_device);
} while ((rc == DEVICE_RETRY || rc == DEVICE_START_UNIT ||
rc == DEVICE_STOP_UNIT || rc == DEVICE_RETRY_UA)
&& count++ <= command_retry_count);
--
2.56.1