From: "Matias Bjørling" <mb@lightnvm.io>
To: Wenwei Tao <ww.tao0320@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH] lightnvm: free allocated memory when gennvm register fails
Date: Mon, 23 Nov 2015 09:47:12 +0100 [thread overview]
Message-ID: <5652D290.8090705@lightnvm.io> (raw)
In-Reply-To: <1448267375-19009-1-git-send-email-ww.tao0320@gmail.com>
On 11/23/2015 09:29 AM, Wenwei Tao wrote:
> free allocated nvm block and gennvm lun structures when
> gennvm register fails, otherwise it will cause memory leak.
>
> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
> ---
> drivers/lightnvm/gennvm.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
> index ae1fb2b..03fc7a5 100644
> --- a/drivers/lightnvm/gennvm.c
> +++ b/drivers/lightnvm/gennvm.c
> @@ -211,12 +211,15 @@ static int gennvm_register(struct nvm_dev *dev)
> ret = gennvm_blocks_init(dev, gn);
> if (ret) {
> pr_err("gennvm: could not initialize blocks\n");
> + gennvm_blocks_free(dev);
> + gennvm_luns_free(dev);
> goto err;
> }
>
> return 1;
> err:
> kfree(gn);
> + dev->mp = NULL;
> return ret;
> }
>
>
Thanks Tao, would it be okay with you if I apply the patch like this:
diff --git i/drivers/lightnvm/gennvm.c w/drivers/lightnvm/gennvm.c
index e20e74e..3969a98 100644
--- i/drivers/lightnvm/gennvm.c
+++ w/drivers/lightnvm/gennvm.c
@@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev,
struct gen_nvm *gn)
return 0;
}
+static void gennvm_free(struct nvm_dev *dev)
+{
+ gennvm_blocks_free(dev);
+ gennvm_luns_free(dev);
+ kfree(dev->mp);
+ dev->mp = NULL;
+}
+
static int gennvm_register(struct nvm_dev *dev)
{
struct gen_nvm *gn;
@@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev)
return 1;
err:
- kfree(gn);
+ gennvm_free(dev);
return ret;
}
static void gennvm_unregister(struct nvm_dev *dev)
{
- gennvm_blocks_free(dev);
- gennvm_luns_free(dev);
- kfree(dev->mp);
- dev->mp = NULL;
+ gennvm_free(dev);
}
next prev parent reply other threads:[~2015-11-23 8:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-23 8:29 [PATCH] lightnvm: free allocated memory when gennvm register fails Wenwei Tao
2015-11-23 8:47 ` Matias Bjørling [this message]
2015-11-23 9:00 ` Wenwei Tao
2015-11-23 9:01 ` Matias Bjørling
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=5652D290.8090705@lightnvm.io \
--to=mb@lightnvm.io \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ww.tao0320@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