linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chad Dupuis <chad.dupuis@qlogic.com>
To: jbottomley@parallels.com
Cc: giridhar.malavali@qlogic.com, chad.dupuis@qlogic.com,
	andrew.vasquez@qlogic.com, linux-scsi@vger.kernel.org
Subject: [PATCH 07/22] qla2xxx: Handle interrupt registration failures more gracefully.
Date: Tue, 15 May 2012 14:34:14 -0400	[thread overview]
Message-ID: <1337106869-14191-8-git-send-email-chad.dupuis@qlogic.com> (raw)
In-Reply-To: <1337106869-14191-1-git-send-email-chad.dupuis@qlogic.com>

If interrupt registration failed we could crash the machine as we were trying
to deference some pointers which weren't allocated yet.  Move the allocation
a little earlier and make some checks to the free resource code to make sure
that we don't try to free a resource that was never allocated.

Signed-off-by: Giridhar Malavali <giridhar.malavali@qlogic.com>
Signed-off-by: Chad Dupuis <chad.dupuis@qlogic.com>
---
 drivers/scsi/qla2xxx/qla_isr.c |   10 ++++++++-
 drivers/scsi/qla2xxx/qla_os.c  |   44 ++++++++++++++++++++++++++++-----------
 2 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index ce42288..f4b8a5f 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2564,7 +2564,15 @@ void
 qla2x00_free_irqs(scsi_qla_host_t *vha)
 {
 	struct qla_hw_data *ha = vha->hw;
-	struct rsp_que *rsp = ha->rsp_q_map[0];
+	struct rsp_que *rsp;
+
+	/*
+	 * We need to check that ha->rsp_q_map is valid in case we are called
+	 * from a probe failure context.
+	 */
+	if (!ha->rsp_q_map || !ha->rsp_q_map[0])
+		return;
+	rsp = ha->rsp_q_map[0];
 
 	if (ha->flags.msix_enabled)
 		qla24xx_disable_msix(ha);
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 7db8033..2e6dd88 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -306,7 +306,8 @@ static void qla2x00_free_fw_dump(struct qla_hw_data *);
 static void qla2x00_mem_free(struct qla_hw_data *);
 
 /* -------------------------------------------------------------------------- */
-static int qla2x00_alloc_queues(struct qla_hw_data *ha)
+static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
+				struct rsp_que *rsp)
 {
 	scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
 	ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
@@ -324,6 +325,12 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha)
 		    "Unable to allocate memory for response queue ptrs.\n");
 		goto fail_rsp_map;
 	}
+	/*
+	 * Make sure we record at least the request and response queue zero in
+	 * case we need to free them if part of the probe fails.
+	 */
+	ha->rsp_q_map[0] = rsp;
+	ha->req_q_map[0] = req;
 	set_bit(0, ha->rsp_qid_map);
 	set_bit(0, ha->req_qid_map);
 	return 1;
@@ -2417,6 +2424,16 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	    host->max_cmd_len, host->max_channel, host->max_lun,
 	    host->transportt, sht->vendor_id);
 
+que_init:
+	/* Alloc arrays of request and response ring ptrs */
+	if (!qla2x00_alloc_queues(ha, req, rsp)) {
+		ql_log(ql_log_fatal, base_vha, 0x003d,
+		    "Failed to allocate memory for queue pointers..."
+		    "aborting.\n");
+		goto probe_init_failed;
+	}
+
+
 	/* Set up the irqs */
 	ret = qla2x00_request_irqs(ha, rsp);
 	if (ret)
@@ -2424,20 +2441,10 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	pci_save_state(pdev);
 
-	/* Alloc arrays of request and response ring ptrs */
-que_init:
-	if (!qla2x00_alloc_queues(ha)) {
-		ql_log(ql_log_fatal, base_vha, 0x003d,
-		    "Failed to allocate memory for queue pointers.. aborting.\n");
-		goto probe_init_failed;
-	}
-
-	ha->rsp_q_map[0] = rsp;
-	ha->req_q_map[0] = req;
+	/* Assign back pointers */
 	rsp->req = req;
 	req->rsp = rsp;
-	set_bit(0, ha->req_qid_map);
-	set_bit(0, ha->rsp_qid_map);
+
 	/* FWI2-capable only. */
 	req->req_q_in = &ha->iobase->isp24.req_q_in;
 	req->req_q_out = &ha->iobase->isp24.req_q_out;
@@ -2581,7 +2588,11 @@ skip_dpc:
 
 probe_init_failed:
 	qla2x00_free_req_que(ha, req);
+	ha->req_q_map[0] = NULL;
+	clear_bit(0, ha->req_qid_map);
 	qla2x00_free_rsp_que(ha, rsp);
+	ha->rsp_q_map[0] = NULL;
+	clear_bit(0, ha->rsp_qid_map);
 	ha->max_req_queues = ha->max_rsp_queues = 0;
 
 probe_failed:
@@ -2663,6 +2674,13 @@ qla2x00_remove_one(struct pci_dev *pdev)
 	struct qla_hw_data  *ha;
 	unsigned long flags;
 
+	/*
+	 * If the PCI device is disabled that means that probe failed and any
+	 * resources should be have cleaned up on probe exit.
+	 */
+	if (!atomic_read(&pdev->enable_cnt))
+		return;
+
 	base_vha = pci_get_drvdata(pdev);
 	ha = base_vha->hw;
 
-- 
1.7.7


  parent reply	other threads:[~2012-05-15 18:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-15 18:34 [PATCH 00/22] qla2xxx: Updates for scsi "misc" branch Chad Dupuis
2012-05-15 18:34 ` [PATCH 01/22] qla2xxx: Fix typo in qla_init.c Chad Dupuis
2012-05-15 18:34 ` [PATCH 02/22] qla2xxx: Micro optimization in queuecommand handler Chad Dupuis
2012-05-15 18:34 ` [PATCH 03/22] qla2xxx: Fix typo in qla_mbx.c Chad Dupuis
2012-05-15 18:34 ` [PATCH 04/22] qla2xxx: Remove unneeded DPC wakeups from qla82xx_watchdog Chad Dupuis
2012-05-15 18:34 ` [PATCH 05/22] qla2xxx: Detect PEG errors Chad Dupuis
2012-05-15 18:34 ` [PATCH 06/22] qla2xxx: Change "Done" to "Entering" in the debug print statement in qla2x00_port_logout Chad Dupuis
2012-05-15 18:34 ` Chad Dupuis [this message]
2012-05-15 18:34 ` [PATCH 08/22] qla2xxx: Add ql_dbg_verbose logging level Chad Dupuis
2012-05-15 18:34 ` [PATCH 09/22] qla2xxx: Stats should be different from physical and virtual ports Chad Dupuis
2012-05-15 18:34 ` [PATCH 10/22] qla2xxx: Fix typo in bus-reset handler Chad Dupuis
2012-05-15 18:34 ` [PATCH 11/22] qla2xxx: Display proper supported speeds for 16G FC adapters Chad Dupuis
2012-05-15 18:34 ` [PATCH 12/22] qla2xxx: Fixups for ISP83xx Chad Dupuis
2012-05-15 18:34 ` [PATCH 13/22] qla2xxx: Remove mirrored field vp_idx from struct fc_port Chad Dupuis
2012-05-15 18:34 ` [PATCH 14/22] qla2xxx: Optimize existing port name server query matching Chad Dupuis
2012-05-15 18:34 ` [PATCH 15/22] qla2xxx: Corrections to log messages Chad Dupuis
2012-05-15 18:34 ` [PATCH 16/22] qla2xxx: Log link up and link down messages to track link flops Chad Dupuis
2012-05-15 18:34 ` [PATCH 17/22] qla2xxx: Avoid losing any fc ports when loop id's are exhausted Chad Dupuis
2012-05-15 18:34 ` [PATCH 18/22] qla2xxx: Don't capture minidump for ISP82xx on flash update from application Chad Dupuis
2012-05-15 18:34 ` [PATCH 19/22] qla2xxx: Display proper firmware version when new minidump template is gathered for ISP82xx Chad Dupuis
2012-05-15 18:34 ` [PATCH 20/22] Revert "qla2xxx: During loopdown perform Diagnostic loopback." Chad Dupuis
2012-05-15 18:34 ` [PATCH 21/22] qla2xxx: Add LLD target-mode infrastructure for >= 24xx series Chad Dupuis
2012-05-15 18:34 ` [PATCH 22/22] tcm_qla2xxx: Add >= 24xx series fabric module for target-core Chad Dupuis
2012-05-18 23:47 ` [PATCH 00/22] qla2xxx: Updates for scsi "misc" branch Nicholas A. Bellinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337106869-14191-8-git-send-email-chad.dupuis@qlogic.com \
    --to=chad.dupuis@qlogic.com \
    --cc=andrew.vasquez@qlogic.com \
    --cc=giridhar.malavali@qlogic.com \
    --cc=jbottomley@parallels.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).