Blob Blame History Raw
From: Andrew Vasquez <andrewv@marvell.com>
Date: Fri, 26 Jul 2019 09:07:35 -0700
Subject: scsi: qla2xxx: Correct error handling during initialization failures
Patch-mainline: v5.4-rc1
Git-commit: 26a77799195f4ff105f877042012c7fb355b3da1
References: bsc#1082635 bsc#1141340 bsc#1143706

Current code misses or fails to account for proper recovery during early
initialization failures:

 - Properly unwind allocations during probe() failures.

 - Protect against non-initialization memory allocations during
   unwinding.

 - Propagate error status during HW initialization.

 - Release SCSI host reference when memory allocations fail.

Signed-off-by: Andrew Vasquez <andrewv@marvell.com>
Signed-off-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Daniel Wagner <dwagner@suse.de>
---
 drivers/scsi/qla2xxx/qla_init.c |    4 ++++
 drivers/scsi/qla2xxx/qla_os.c   |   12 +++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -2295,6 +2295,10 @@ qla2x00_initialize_adapter(scsi_qla_host
 	if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
 		rval = qla2x00_init_rings(vha);
 
+	/* No point in continuing if firmware initialization failed. */
+	if (rval != QLA_SUCCESS)
+		return rval;
+
 	ha->flags.chip_reset_done = 1;
 
 	if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1811,8 +1811,13 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *
 	int que;
 	struct qla_hw_data *ha = vha->hw;
 
+	/* Continue only if initialization complete. */
+	if (!ha->base_qpair)
+		return;
 	__qla2x00_abort_all_cmds(ha->base_qpair, res);
 
+	if (!ha->queue_pair_map)
+		return;
 	for (que = 0; que < ha->max_qpairs; que++) {
 		if (!ha->queue_pair_map[que])
 			continue;
@@ -3165,6 +3170,7 @@ qla2x00_probe_one(struct pci_dev *pdev,
 		ql_log(ql_log_fatal, base_vha, 0x003d,
 		    "Failed to allocate memory for queue pointers..."
 		    "aborting.\n");
+		ret = -ENODEV;
 		goto probe_failed;
 	}
 
@@ -4726,7 +4732,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
 	mempool_destroy(ha->ctx_mempool);
 	ha->ctx_mempool = NULL;
 
-	if (ql2xenabledif) {
+	if (ql2xenabledif && ha->dif_bundl_pool) {
 		struct dsd_dma *dsd, *nxt;
 
 		list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
@@ -4828,7 +4834,7 @@ struct scsi_qla_host *qla2x00_create_hos
 	if (!vha->gnl.l) {
 		ql_log(ql_log_fatal, vha, 0xd04a,
 		    "Alloc failed for name list.\n");
-		scsi_remove_host(vha->host);
+		scsi_host_put(vha->host);
 		return NULL;
 	}
 
@@ -4840,7 +4846,7 @@ struct scsi_qla_host *qla2x00_create_hos
 		    "Alloc failed for scan database.\n");
 		dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
 		    vha->gnl.l, vha->gnl.ldma);
-		scsi_remove_host(vha->host);
+		scsi_host_put(vha->host);
 		return NULL;
 	}
 	INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);