scsi: lpfc: Fix memory leak on lcb_context

Currently there is an error return path that neglects to free the
allocation for lcb_context.  Fix this by adding a new error free exit path
that kfree's lcb_context before returning.  Use this new kfree exit path in
another exit error path that also kfree's the same object, allowing a line
of code to be removed.

Link: https://lore.kernel.org/r/20201118141314.462471-1-colin.king@canonical.com
Fixes: 4430f7fd09 ("scsi: lpfc: Rework locations of ndlp reference taking")
Reviewed-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Addresses-Coverity: ("Resource leak")
This commit is contained in:
Colin Ian King 2020-11-18 14:13:14 +00:00 committed by Martin K. Petersen
parent 61795a5316
commit 14c1dd9504
1 changed files with 5 additions and 3 deletions

View File

@ -6515,18 +6515,20 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
lcb_context->ndlp = lpfc_nlp_get(ndlp); lcb_context->ndlp = lpfc_nlp_get(ndlp);
if (!lcb_context->ndlp) { if (!lcb_context->ndlp) {
rjt_err = LSRJT_UNABLE_TPC; rjt_err = LSRJT_UNABLE_TPC;
goto rjt; goto rjt_free;
} }
if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
"0193 failed to send mail box"); "0193 failed to send mail box");
kfree(lcb_context);
lpfc_nlp_put(ndlp); lpfc_nlp_put(ndlp);
rjt_err = LSRJT_UNABLE_TPC; rjt_err = LSRJT_UNABLE_TPC;
goto rjt; goto rjt_free;
} }
return 0; return 0;
rjt_free:
kfree(lcb_context);
rjt: rjt:
memset(&stat, 0, sizeof(stat)); memset(&stat, 0, sizeof(stat));
stat.un.b.lsRjtRsnCode = rjt_err; stat.un.b.lsRjtRsnCode = rjt_err;