mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Naresh Kumar Inna <naresh@chelsio.com>
To: Jesper Juhl <jj@chaosbits.net>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] [SCSI] csiostor: Don't leak mem or fail to release firmware in csio_hw_flash_config()
Date: Fri, 28 Dec 2012 16:59:30 +0530	[thread overview]
Message-ID: <50DD829A.1080503@chelsio.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1212262129490.23814@swampdragon.chaosbits.net>

On 12/27/2012 2:01 AM, Jesper Juhl wrote:
> If kzalloc() or csio_hw_check_fwconfig() fail we may leave the
> csio_hw_flash_config() function without freeing allocated memory or
> firmware. This should take care of the leaks.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  drivers/scsi/csiostor/csio_hw.c |   15 +++++++++------
>  1 files changed, 9 insertions(+), 6 deletions(-)
> 
>  Note: I'm unable to really test this, so the patch is compile tested
>        only.
> 
> diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
> index 8ecdb94..bdd78fb 100644
> --- a/drivers/scsi/csiostor/csio_hw.c
> +++ b/drivers/scsi/csiostor/csio_hw.c
> @@ -2131,13 +2131,16 @@ csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
>  		value_to_add = 4 - (cf->size % 4);
>  
>  	cfg_data = kzalloc(cf->size+value_to_add, GFP_KERNEL);
> -	if (cfg_data == NULL)
> -		return -ENOMEM;
> +	if (cfg_data == NULL) {
> +		ret = -ENOMEM;
> +		goto leave;
> +	}
>  
>  	memcpy((void *)cfg_data, (const void *)cf->data, cf->size);
> -
> -	if (csio_hw_check_fwconfig(hw, fw_cfg_param) != 0)
> -		return -EINVAL;
> +	if (csio_hw_check_fwconfig(hw, fw_cfg_param) != 0) {
> +		ret = -EINVAL;
> +		goto leave;
> +	}
>  
>  	mtype = FW_PARAMS_PARAM_Y_GET(*fw_cfg_param);
>  	maddr = FW_PARAMS_PARAM_Z_GET(*fw_cfg_param) << 16;
> @@ -2149,9 +2152,9 @@ csio_hw_flash_config(struct csio_hw *hw, u32 *fw_cfg_param, char *path)
>  		strncpy(path, "/lib/firmware/" CSIO_CF_FNAME, 64);
>  	}
>  
> +leave:
>  	kfree(cfg_data);
>  	release_firmware(cf);
> -
>  	return ret;
>  }
>  
> 

Acked-by: Naresh Kumar Inna <naresh@chelsio.com>

Thanks,
Naresh.

      reply	other threads:[~2012-12-28 11:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-26 20:31 Jesper Juhl
2012-12-28 11:29 ` Naresh Kumar Inna [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=50DD829A.1080503@chelsio.com \
    --to=naresh@chelsio.com \
    --cc=JBottomley@parallels.com \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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

Powered by JetHome