public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Smart <james.smart@avagotech.com>
To: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	Dick Kennedy <dick.kennedy@avagotech.com>,
	"James E.J. Bottomley" <JBottomley@odin.com>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] lpfc: fix memory leak and NULL dereference
Date: Mon, 12 Oct 2015 11:02:29 -0700	[thread overview]
Message-ID: <561BF5B5.4080901@avagotech.com> (raw)
In-Reply-To: <1443015152-12301-1-git-send-email-sudipm.mukherjee@gmail.com>

Looks Good - Thank you Sudip.

Reviewed-by: James Smart <james.smart@avagotech.com>

-- james s


On 9/23/2015 6:32 AM, Sudip Mukherjee wrote:
> 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>
> ---
>
> I am not exactly sure if LSRJT_UNABLE_TPC is the right error code here.
> But that was my best guess.
>
>   drivers/scsi/lpfc/lpfc_els.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
> index 36bf58b..a27efd9 100644
> --- a/drivers/scsi/lpfc/lpfc_els.c
> +++ b/drivers/scsi/lpfc/lpfc_els.c
> @@ -5209,7 +5209,6 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
>   		rjt_err = LSRJT_CMD_UNSUPPORTED;
>   		goto rjt;
>   	}
> -	lcb_context = kmalloc(sizeof(struct lpfc_lcb_context), GFP_KERNEL);
>   
>   	if (phba->hba_flag & HBA_FCOE_MODE) {
>   		rjt_err = LSRJT_CMD_UNSUPPORTED;
> @@ -5240,6 +5239,12 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
>   		goto rjt;
>   	}
>   
> +	lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
> +	if (!lcb_context) {
> +		rjt_err = LSRJT_UNABLE_TPC;
> +		goto rjt;
> +	}
> +
>   	state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
>   	lcb_context->sub_command = beacon->lcb_sub_command;
>   	lcb_context->type = beacon->lcb_type;
> @@ -5250,6 +5255,7 @@ lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
>   	if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
>   		lpfc_printf_vlog(ndlp->vport, KERN_ERR,
>   				 LOG_ELS, "0193 failed to send mail box");
> +		kfree(lcb_context);
>   		lpfc_nlp_put(ndlp);
>   		rjt_err = LSRJT_UNABLE_TPC;
>   		goto rjt;


      parent reply	other threads:[~2015-10-12 18:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23 13:32 [PATCH] lpfc: fix memory leak and NULL dereference Sudip Mukherjee
2015-10-08 14:20 ` Sudip Mukherjee
2015-10-12 18:02 ` James Smart [this message]

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=561BF5B5.4080901@avagotech.com \
    --to=james.smart@avagotech.com \
    --cc=JBottomley@odin.com \
    --cc=dick.kennedy@avagotech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox