All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matias Bjørling" <m@bjorling.me>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com
Cc: hch@infradead.org, keith.busch@intel.com,
	sudipm.mukherjee@gmail.com, ww.tao0320@gmail.com,
	"Matias Bjørling" <m@bjorling.me>
Subject: [PATCH 3/5] lightnvm: free memory when gennvm register fails
Date: Tue, 24 Nov 2015 14:26:46 +0100	[thread overview]
Message-ID: <1448371608-18053-4-git-send-email-m@bjorling.me> (raw)
In-Reply-To: <1448371608-18053-1-git-send-email-m@bjorling.me>

From: Wenwei Tao <ww.tao0320@gmail.com>

free allocated nvm block and gennvm lun structures when
gennvm register fails, otherwise it will cause memory leak.

Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/gennvm.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index e20e74e..3969a98 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/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);
 }
 
 static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev,
-- 
2.1.4


  parent reply	other threads:[~2015-11-24 13:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 13:26 [PATCH 0/5] LightNVM fixes Matias Bjørling
2015-11-24 13:26 ` [PATCH 1/5] lightnvm: change vendor and dev id for qemu Matias Bjørling
2015-11-24 15:52   ` Elliott, Robert (Persistent Memory)
2015-11-24 18:24     ` Matias Bjørling
2015-11-24 22:21       ` Jens Axboe
2015-11-24 13:26 ` [PATCH 2/5] lightnvm: Simplify config when disabled Matias Bjørling
2015-11-24 13:26 ` Matias Bjørling [this message]
2015-11-24 13:26 ` [PATCH 4/5] lightnvm: fix ioctl memory leaks Matias Bjørling
2015-11-24 13:26 ` [PATCH 5/5] lightnvm: do device max sectors boundary check first 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=1448371608-18053-4-git-send-email-m@bjorling.me \
    --to=m@bjorling.me \
    --cc=axboe@fb.com \
    --cc=hch@infradead.org \
    --cc=keith.busch@intel.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.