Skip to contentSkip to conversation

lpfc: Correct null ndlp reference on routine exit

PATCH Applied James Smart 2 participants 3 messages Nov 30, 2020 – Dec 8, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lpfc: Correct null ndlp reference on routine exit

smatch correctly called out a logic error with accessing a pointer after checking it for null.
drivers/scsi/lpfc/lpfc_els.c:2043 lpfc_cmpl_els_plogi()
error: we previously assumed 'ndlp' could be null (see line 1942)

Adjust the exit point to avoid the trace printf ndlp reference. A trace entry was already generated when the ndlp was checked for null.

Fixes 4430f7fd09ec ("scsi: lpfc: Rework locations of ndlp reference taking")
---
 drivers/scsi/lpfc/lpfc_els.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_els.c +2 -1
index fd5c581cd67a..96c087b8b474 100644
@@ -1946,7 +1946,7 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 				 irsp->un.elsreq64.remoteID,
 				 irsp->ulpStatus, irsp->un.ulpWord[4],
 				 irsp->ulpIoTag);
-		goto out;
+		goto out_freeiocb;
 	}
 
 	/* Since ndlp can be freed in the disc state machine, note if this node
@@ -2042,6 +2042,7 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 			      "PLOGI Cmpl PUT:     did:x%x refcnt %d",
 			      ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
 
+out_freeiocb:
 	/* Release the reference on the original I/O request. */
 	free_ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
 
Signature · 1 line
2.26.2
#1 lore raw

James,

Quoted 7 lines

smatch correctly called out a logic error with accessing a pointer after checking it for null.
drivers/scsi/lpfc/lpfc_els.c:2043 lpfc_cmpl_els_plogi()
error: we previously assumed 'ndlp' could be null (see line 1942)

Adjust the exit point to avoid the trace printf ndlp reference. A trace entry was already generated when the ndlp was checked for null.

Applied to 5.11/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
In reply to James Smart
Quoted 7 lines · James Smart

smatch correctly called out a logic error with accessing a pointer after checking it for null.
drivers/scsi/lpfc/lpfc_els.c:2043 lpfc_cmpl_els_plogi()
error: we previously assumed 'ndlp' could be null (see line 1942)

Adjust the exit point to avoid the trace printf ndlp reference. A trace entry was already generated when the ndlp was checked for null.

Applied to 5.11/scsi-queue, thanks!

[1/1] lpfc: Correct null ndlp reference on routine exit

      https://git.kernel.org/mkp/scsi/c/9d8de441db26
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering