diff mbox

scsi: lpfc: Fix potential NULL pointer dereference in lpfc_nvme_fcp_io_submit

Message ID 20171127135230.GA4546@embeddedor.com (mailing list archive)
State Deferred
Headers show

Commit Message

Gustavo A. R. Silva Nov. 27, 2017, 1:52 p.m. UTC
pnvme_lport is being dereferenced before it is null checked, hence there
is a potential null pointer dereference.

Fix this by null checking pnvme_lport before it is dereferenced.

Addresses-Coverity-ID: 1423709 ("Dereference before null check")
Fixes: b7672ae681f8 ("scsi: lpfc: Fix crash in lpfc_nvme_fcp_io_submit during LIP")
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
Also, I wonder if the right pointer to check at line:

if (!pnvme_rport || !freqpriv) {

is pnvme_fcreq instead of freqpriv

 drivers/scsi/lpfc/lpfc_nvme.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index 517ae57..68cba7d 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -1251,6 +1251,11 @@  lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
 	uint64_t start = 0;
 #endif
 
+	if (!pnvme_lport) {
+		ret = -ENODEV;
+		goto out_fail;
+	}
+
 	lport = (struct lpfc_nvme_lport *)pnvme_lport->private;
 	vport = lport->vport;
 	phba = vport->phba;
@@ -1261,7 +1266,7 @@  lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
 	}
 
 	/* Validate pointers. */
-	if (!pnvme_lport || !pnvme_rport || !freqpriv) {
+	if (!pnvme_rport || !freqpriv) {
 		lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR | LOG_NODE,
 				 "6117 No Send:IO submit ptrs NULL, lport %p, "
 				 "rport %p fcreq_priv %p\n",