All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chad Dupuis <chad.dupuis@qlogic.com>
To: jejb@linux.vnet.ibm.com, martin.petersen@oracle.com
Cc: chad.dupuis@qlogic.com, saurav.kashyap@qlogic.com,
	linux-scsi@vger.kernel.org
Subject: [PATCH 4/5] bnx2fc: Check sc_cmd device and host pointer before returning the command to the mid-layer.
Date: Fri, 1 Apr 2016 09:10:22 -0400	[thread overview]
Message-ID: <1459516223-32106-5-git-send-email-chad.dupuis@qlogic.com> (raw)
In-Reply-To: <1459516223-32106-1-git-send-email-chad.dupuis@qlogic.com>

When we are in connection recovery and the internal command timer on a request
pops, either the scsi_cmnd->device or scsi_cmnd->device->host back pointers may
be NULL as the device that the command that the request was submitted on may
have been subsequently reaped due to the connection recovery. This can cause
one or both of the pointers above to be NULL and cause a system crash if we try
to return the command to the midlayer.

Instead, double check the pointers before the return to the midlayer so as to
prevent the crash and let the upper layers finish the session recovery and
rediscover the device.

Signed-off-by: Chad Dupuis <chad.dupuis@qlogic.com>
---
 drivers/scsi/bnx2fc/bnx2fc_io.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 0f60e22..33e519d 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -181,12 +181,24 @@ static void bnx2fc_scsi_done(struct bnx2fc_cmd *io_req, int err_code)
 
 	bnx2fc_unmap_sg_list(io_req);
 	io_req->sc_cmd = NULL;
+
+	/* Sanity checks before returning command to mid-layer */
 	if (!sc_cmd) {
 		printk(KERN_ERR PFX "scsi_done - sc_cmd NULL. "
 				    "IO(0x%x) already cleaned up\n",
 		       io_req->xid);
 		return;
 	}
+	if (!sc_cmd->device) {
+		pr_err(PFX "0x%x: sc_cmd->device is NULL.\n", io_req->xid);
+		return;
+	}
+	if (!sc_cmd->device->host) {
+		pr_err(PFX "0x%x: sc_cmd->device->host is NULL.\n",
+		    io_req->xid);
+		return;
+	}
+
 	sc_cmd->result = err_code << 16;
 
 	BNX2FC_IO_DBG(io_req, "sc=%p, result=0x%x, retries=%d, allowed=%d\n",
-- 
2.0.0.rc0.26.g779792a


  parent reply	other threads:[~2016-04-01 13:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01 13:10 [PATCH 0/5] bnx2fc: Update driver to 2.10.3 Chad Dupuis
2016-04-01 13:10 ` [PATCH 1/5] bnx2fc: Add driver tunables Chad Dupuis
2016-04-01 13:56   ` Johannes Thumshirn
2016-04-01 14:06     ` Chad Dupuis
2016-04-01 18:57       ` James Bottomley
2016-04-04 14:23         ` Chad Dupuis
2016-04-04  7:01       ` Johannes Thumshirn
2016-04-01 13:10 ` [PATCH 2/5] bnx2fc: Print when we send a fip keep alive Chad Dupuis
2016-04-01 13:57   ` Johannes Thumshirn
2016-04-01 13:10 ` [PATCH 3/5] bnx2fc: Print netdev device name when FCoE is successfully initialized Chad Dupuis
2016-04-01 13:58   ` Johannes Thumshirn
2016-04-01 14:08     ` Chad Dupuis
2016-04-01 13:10 ` Chad Dupuis [this message]
2016-04-01 14:02   ` [PATCH 4/5] bnx2fc: Check sc_cmd device and host pointer before returning the command to the mid-layer Johannes Thumshirn
2016-04-01 13:10 ` [PATCH 5/5] bnx2fc: Update version number to 2.10.3 Chad Dupuis
2016-04-01 14:02   ` Johannes Thumshirn

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=1459516223-32106-5-git-send-email-chad.dupuis@qlogic.com \
    --to=chad.dupuis@qlogic.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=saurav.kashyap@qlogic.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.