Blame SOURCES/0115-scsi-scsi-qla2xxx-Correct-error-handling-during-init.patch

3d7c23
From 0ee7d9ad01f4885ddec721d3bfb3b161709efb66 Mon Sep 17 00:00:00 2001
3d7c23
From: Himanshu Madhani <hmadhani@redhat.com>
3d7c23
Date: Thu, 1 Aug 2019 15:56:15 -0400
3d7c23
Subject: [PATCH 115/124] [scsi] scsi: qla2xxx: Correct error handling during
3d7c23
 initialization failures
3d7c23
3d7c23
Message-id: <20190801155618.12650-116-hmadhani@redhat.com>
3d7c23
Patchwork-id: 267876
3d7c23
O-Subject: [RHEL 7.8 e-stor PATCH 115/118] scsi: qla2xxx: Correct error handling during initialization failures
3d7c23
Bugzilla: 1729270
3d7c23
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
3d7c23
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
3d7c23
3d7c23
From: Andrew Vasquez <andrewv@marvell.com>
3d7c23
3d7c23
Bugzilla 1729270
3d7c23
3d7c23
Current code misses or fails to account for proper recovery during early
3d7c23
initialization failures:
3d7c23
3d7c23
 - Properly unwind allocations during probe() failures.
3d7c23
3d7c23
 - Protect against non-initialization memory allocations during
3d7c23
   unwinding.
3d7c23
3d7c23
 - Propagate error status during HW initialization.
3d7c23
3d7c23
 - Release SCSI host reference when memory allocations fail.
3d7c23
3d7c23
Signed-off-by: Andrew Vasquez <andrewv@marvell.com>
3d7c23
Signed-off-by: Himanshu Madhani <hmadhani@marvell.com>
3d7c23
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
3d7c23
(cherry picked from commit 9e6d7196449711306cbe385a312be953e5100063)
3d7c23
Signed-off-by: Himanshu Madhani <hmadhani@redhat.com>
3d7c23
Signed-off-by: Jan Stancek <jstancek@redhat.com>
3d7c23
---
3d7c23
 drivers/scsi/qla2xxx/qla_init.c |  4 ++++
3d7c23
 drivers/scsi/qla2xxx/qla_os.c   | 12 +++++++++---
3d7c23
 2 files changed, 13 insertions(+), 3 deletions(-)
3d7c23
3d7c23
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
3d7c23
index 22e3dcd3ab62..65d8b8faadba 100644
3d7c23
--- a/drivers/scsi/qla2xxx/qla_init.c
3d7c23
+++ b/drivers/scsi/qla2xxx/qla_init.c
3d7c23
@@ -2280,6 +2280,10 @@ qla2x00_initialize_adapter(scsi_qla_host_t *vha)
3d7c23
 	if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
3d7c23
 		rval = qla2x00_init_rings(vha);
3d7c23
 
3d7c23
+	/* No point in continuing if firmware initialization failed. */
3d7c23
+	if (rval != QLA_SUCCESS)
3d7c23
+		return rval;
3d7c23
+
3d7c23
 	ha->flags.chip_reset_done = 1;
3d7c23
 
3d7c23
 	if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
3d7c23
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
3d7c23
index 10e05c60a2d7..2e96a41839e0 100644
3d7c23
--- a/drivers/scsi/qla2xxx/qla_os.c
3d7c23
+++ b/drivers/scsi/qla2xxx/qla_os.c
3d7c23
@@ -1851,8 +1851,13 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
3d7c23
 	int que;
3d7c23
 	struct qla_hw_data *ha = vha->hw;
3d7c23
 
3d7c23
+	/* Continue only if initialization complete. */
3d7c23
+	if (!ha->base_qpair)
3d7c23
+		return;
3d7c23
 	__qla2x00_abort_all_cmds(ha->base_qpair, res);
3d7c23
 
3d7c23
+	if (!ha->queue_pair_map)
3d7c23
+		return;
3d7c23
 	for (que = 0; que < ha->max_qpairs; que++) {
3d7c23
 		if (!ha->queue_pair_map[que])
3d7c23
 			continue;
3d7c23
@@ -3278,6 +3283,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
3d7c23
 		ql_log(ql_log_fatal, base_vha, 0x003d,
3d7c23
 		    "Failed to allocate memory for queue pointers..."
3d7c23
 		    "aborting.\n");
3d7c23
+		ret = -ENODEV;
3d7c23
 		goto probe_failed;
3d7c23
 	}
3d7c23
 
3d7c23
@@ -4843,7 +4849,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
3d7c23
 	mempool_destroy(ha->ctx_mempool);
3d7c23
 	ha->ctx_mempool = NULL;
3d7c23
 
3d7c23
-	if (ql2xenabledif) {
3d7c23
+	if (ql2xenabledif && ha->dif_bundl_pool) {
3d7c23
 		struct dsd_dma *dsd, *nxt;
3d7c23
 
3d7c23
 		list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
3d7c23
@@ -4939,7 +4945,7 @@ struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3d7c23
 	if (!vha->gnl.l) {
3d7c23
 		ql_log(ql_log_fatal, vha, 0xd04a,
3d7c23
 		    "Alloc failed for name list.\n");
3d7c23
-		scsi_remove_host(vha->host);
3d7c23
+		scsi_host_put(vha->host);
3d7c23
 		return NULL;
3d7c23
 	}
3d7c23
 
3d7c23
@@ -4951,7 +4957,7 @@ struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3d7c23
 		    "Alloc failed for scan database.\n");
3d7c23
 		dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
3d7c23
 		    vha->gnl.l, vha->gnl.ldma);
3d7c23
-		scsi_remove_host(vha->host);
3d7c23
+		scsi_host_put(vha->host);
3d7c23
 		return NULL;
3d7c23
 	}
3d7c23
 	INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
3d7c23
-- 
3d7c23
2.13.6
3d7c23