[PATCH 1/4] scsi: mptfusion: Put the SCSI device in mptspi_write_spi_device_pg1()

From: Wentao Liang

Date: Tue Nov 03 2026 - 04:56:58 EST


mptspi_write_spi_device_pg1() walks the LUNs of the target looking for a
tape device so that inline data padding can be enabled for it. The loop
uses scsi_device_lookup_by_target(), which takes a reference on the
returned scsi_device, but the reference is never dropped: not when the
LUN turns out not to be a tape and not when the loop is left after a tape
has been found. Every SPI negotiation that runs with a minimum sync
period of 8 therefore leaks one reference to a SCSI device and keeps the
device from being released.

Release the reference with scsi_device_put() both before moving on to the
next LUN and before leaving the loop.

Fixes: 19fff154e7ee ("[SCSI] mptfusion: Adding inline data padding support for TAPE drive.")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/message/fusion/mptspi.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 56892b1f3de2..9c513ba9fe05 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -914,8 +914,11 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
nego_parms |= MPI_SCSIDEVPAGE1_RP_IDP;
pg1->RequestedParameters =
cpu_to_le32(nego_parms);
+ scsi_device_put(sdev);
break;
}
+ if (sdev)
+ scsi_device_put(sdev);
}
}

--
2.34.1