[PATCH] scsi: mpt3sas: Fix pcie_device reference leak in _scsih_ublock_io_device_wait()
From: Wentao Liang
Date: Thu Sep 17 2026 - 11:23:21 EST
The reference taken by mpt3sas_get_pdev_by_handle() is only dropped at
the bottom of the retry loop. When the device is not ready the loop
takes the continue before that point, so the reference is leaked on
every retry.
Drop the reference right after the reset parameters have been read, so
it is always released once per iteration.
Fixes: aee682fad6cd ("scsi: mpt3sas: Improve device discovery and readiness handling for slow devices")
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
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 12caffeed3a0..c841fe1706c7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4093,6 +4093,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);
@@ -4114,8 +4116,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.34.1