mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Thumshirn <jthumshirn@suse.de>
To: "Matias Bjørling" <m@bjorling.me>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-block-owner@vger.kernel.org
Subject: Re: [PATCH 5/5] lightnvm: avoid memory leak when lun_map kcalloc fails
Date: Tue, 05 Apr 2016 17:14:04 +0200	[thread overview]
Message-ID: <76c2b3dbd424963c24b7b8f7ff479fd8@suse.de> (raw)
In-Reply-To: <1459868131-15133-6-git-send-email-m@bjorling.me>

On 2016-04-05 16:55, Matias Bjørling wrote:
> A memory leak occurs if the lower page table is initialized and the
> following dev->lun_map fails on allocation.
> 
> Rearrange the initialization of lower page table to allow dev->lun_map
> to fail gracefully without memory leak.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Matias Bjørling <m@bjorling.me>
> ---
>  drivers/lightnvm/core.c | 51 
> ++++++++++++++++++++++++++++---------------------
>  1 file changed, 29 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 4cadbe0..fd5a9f3 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -504,6 +504,7 @@ static int nvm_core_init(struct nvm_dev *dev)
>  {
>  	struct nvm_id *id = &dev->identity;
>  	struct nvm_id_group *grp = &id->groups[0];
> +	int ret;
> 
>  	/* device values */
>  	dev->nr_chnls = grp->num_ch;
> @@ -522,33 +523,16 @@ static int nvm_core_init(struct nvm_dev *dev)
>  	dev->plane_mode = NVM_PLANE_SINGLE;
>  	dev->max_rq_size = dev->ops->max_phys_sect * dev->sec_size;
> 
> -	if (grp->mtype != 0) {
> -		pr_err("nvm: memory type not supported\n");
> -		return -EINVAL;
> -	}
> -
> -	switch (grp->fmtype) {
> -	case NVM_ID_FMTYPE_SLC:
> -		if (nvm_init_slc_tbl(dev, grp))
> -			return -ENOMEM;
> -		break;
> -	case NVM_ID_FMTYPE_MLC:
> -		if (nvm_init_mlc_tbl(dev, grp))
> -			return -ENOMEM;
> -		break;
> -	default:
> -		pr_err("nvm: flash type not supported\n");
> -		return -EINVAL;
> -	}
> -
> -	if (!dev->lps_per_blk)
> -		pr_info("nvm: lower page programming table missing\n");
> -
>  	if (grp->mpos & 0x020202)
>  		dev->plane_mode = NVM_PLANE_DOUBLE;
>  	if (grp->mpos & 0x040404)
>  		dev->plane_mode = NVM_PLANE_QUAD;
> 
> +	if (grp->mtype != 0) {
> +		pr_err("nvm: memory type not supported\n");
> +		return -EINVAL;
> +	}
> +
>  	/* calculated values */
>  	dev->sec_per_pl = dev->sec_per_pg * dev->nr_planes;
>  	dev->sec_per_blk = dev->sec_per_pl * dev->pgs_per_blk;
> @@ -560,11 +544,34 @@ static int nvm_core_init(struct nvm_dev *dev)
>  					sizeof(unsigned long), GFP_KERNEL);
>  	if (!dev->lun_map)
>  		return -ENOMEM;
> +
> +	switch (grp->fmtype) {
> +	case NVM_ID_FMTYPE_SLC:
> +		if (nvm_init_slc_tbl(dev, grp)) {
> +			ret = -ENOMEM;
> +			goto err_fmtype;
> +		}
> +		break;
> +	case NVM_ID_FMTYPE_MLC:
> +		if (nvm_init_mlc_tbl(dev, grp)) {
> +			ret = -ENOMEM;
> +			goto err_fmtype;
> +		}
> +		break;
> +	default:
> +		pr_err("nvm: flash type not supported\n");
> +		ret = -EINVAL;
> +		goto err_fmtype;
> +	}
> +
>  	INIT_LIST_HEAD(&dev->online_targets);
>  	mutex_init(&dev->mlock);
>  	spin_lock_init(&dev->lock);
> 
>  	return 0;
> +err_fmtype:
> +	kfree(dev->lun_map);
> +	return ret;
>  }
> 
>  static void nvm_free(struct nvm_dev *dev)

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

      reply	other threads:[~2016-04-05 15:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 14:55 [PATCH 0/5] Fixes to LightNVM Matias Bjørling
2016-04-05 14:55 ` [PATCH 1/5] lightnvm: handle submit_io failure Matias Bjørling
2016-04-05 15:04   ` Johannes Thumshirn
2016-04-05 14:55 ` [PATCH 2/5] lightnvm: implement nvm_submit_ppa_list Matias Bjørling
2016-04-05 15:07   ` Johannes Thumshirn
2016-04-05 14:55 ` [PATCH 3/5] lightnvm: add fpg_size and pfpg_size to struct nvm_dev Matias Bjørling
2016-04-05 15:09   ` Johannes Thumshirn
2016-04-05 14:55 ` [PATCH 4/5] lightnvm: move block fold outside of get_bb_tbl() Matias Bjørling
2016-04-05 15:12   ` Johannes Thumshirn
2016-04-05 14:55 ` [PATCH 5/5] lightnvm: avoid memory leak when lun_map kcalloc fails Matias Bjørling
2016-04-05 15:14   ` Johannes Thumshirn [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=76c2b3dbd424963c24b7b8f7ff479fd8@suse.de \
    --to=jthumshirn@suse.de \
    --cc=linux-block-owner@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m@bjorling.me \
    /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