[PATCH] scsi: mpi3mr: unwind failed remote-PHY allocations

Slavin Liu posted 1 patch 1 week, 4 days ago
drivers/scsi/mpi3mr/mpi3mr_transport.c | 11 +++++++++++
1 file changed, 11 insertions(+)
[PATCH] scsi: mpi3mr: unwind failed remote-PHY allocations
Posted by Slavin Liu 1 week, 4 days ago
Remote-PHY allocation can fail after the SAS port and its PHY links
were registered. Remove those links, delete the port and clear the
pending flag before entering the existing private-port cleanup.

Detected by static analysis and reviewed with AI-assisted source auditing.

Fixes: 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port")
Assisted-by: LLM
Signed-off-by: Slavin Liu <bolin.liu@seu.edu.cn>
---
 drivers/scsi/mpi3mr/mpi3mr_transport.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c
index 232af978d737..4aa443124ab9 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_transport.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c
@@ -1461,6 +1461,17 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
 		rphy = sas_expander_alloc(port,
 		    mr_sas_port->remote_identify.device_type);
 	}
+	if (!rphy) {
+		list_for_each_entry(mr_sas_phy, &mr_sas_port->phy_list,
+				    port_siblings) {
+			sas_port_delete_phy(port, mr_sas_phy->phy);
+			mr_sas_phy->phy_belongs_to_port = 0;
+		}
+		sas_port_delete(port);
+		if (tgtdev)
+			tgtdev->dev_spec.sas_sata_inf.pend_sas_rphy_add = 0;
+		goto out_fail;
+	}
 	rphy->identify = mr_sas_port->remote_identify;
 
 	if (mrioc->current_event)