aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>2015-09-23 09:32:32 -0400
committerJames Bottomley <JBottomley@Odin.com>2015-11-09 20:08:03 -0500
commite79504236548e4c909959ba444f87a12224555ac (patch)
tree645f887cadd3c3fefd4c697d83a2d3c0dc3be9af /drivers
parent481ebb3daac39c6c1a8f78f98b823a9c9591616f (diff)
lpfc: fix memory leak and NULL dereference
kmalloc() can return NULL and without checking we were dereferencing it. Moreover if kmalloc succeeds but the function fails in other parts then we were returning the error code but we missed freeing lcb_context. While at it fixed one related checkpatch warning. Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org> Reviewed-by: James Smart <james.smart@avagotech.com> Signed-off-by: James Bottomley <JBottomley@Odin.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 3feeb447b740..b6fa257ea3e0 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -5173,7 +5173,6 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5173 rjt_err = LSRJT_CMD_UNSUPPORTED; 5173 rjt_err = LSRJT_CMD_UNSUPPORTED;
5174 goto rjt; 5174 goto rjt;
5175 } 5175 }
5176 lcb_context = kmalloc(sizeof(struct lpfc_lcb_context), GFP_KERNEL);
5177 5176
5178 if (phba->hba_flag & HBA_FCOE_MODE) { 5177 if (phba->hba_flag & HBA_FCOE_MODE) {
5179 rjt_err = LSRJT_CMD_UNSUPPORTED; 5178 rjt_err = LSRJT_CMD_UNSUPPORTED;
@@ -5204,6 +5203,12 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5204 goto rjt; 5203 goto rjt;
5205 } 5204 }
5206 5205
5206 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5207 if (!lcb_context) {
5208 rjt_err = LSRJT_UNABLE_TPC;
5209 goto rjt;
5210 }
5211
5207 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; 5212 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5208 lcb_context->sub_command = beacon->lcb_sub_command; 5213 lcb_context->sub_command = beacon->lcb_sub_command;
5209 lcb_context->type = beacon->lcb_type; 5214 lcb_context->type = beacon->lcb_type;
@@ -5214,6 +5219,7 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5214 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { 5219 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5215 lpfc_printf_vlog(ndlp->vport, KERN_ERR, 5220 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5216 LOG_ELS, "0193 failed to send mail box"); 5221 LOG_ELS, "0193 failed to send mail box");
5222 kfree(lcb_context);
5217 lpfc_nlp_put(ndlp); 5223 lpfc_nlp_put(ndlp);
5218 rjt_err = LSRJT_UNABLE_TPC; 5224 rjt_err = LSRJT_UNABLE_TPC;
5219 goto rjt; 5225 goto rjt;