mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dongbo Cao <cdbdyx@163.com>
To: colyli@suse.de
Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org,
	linux-kernel@vger.kernel.org, Dongbo Cao <cdbdyx@163.com>
Subject: [PATCH 2/2] fix potential memory leak in function "register_bcache"
Date: Wed, 15 Aug 2018 14:50:06 +0800	[thread overview]
Message-ID: <20180815065006.19856-1-cdbdyx@163.com> (raw)

if register_cache get error, memory pointed by ca should be released.
and also, blkdev_put should be called I think.

Signed-off-by: Dongbo Cao <cdbdyx@163.com>
---
 drivers/md/bcache/super.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index f98352d4..14c31e03 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2159,6 +2159,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	struct cache_sb *sb = NULL;
 	struct block_device *bdev = NULL;
 	struct page *sb_page = NULL;
+	struct cache *ca = NULL;
 
 	if (!try_module_get(THIS_MODULE))
 		return -EBUSY;
@@ -2206,12 +2207,12 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 		register_bdev(sb, sb_page, bdev, dc);
 		mutex_unlock(&bch_register_lock);
 	} else {
-		struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
+		ca = kzalloc(sizeof(struct cache), GFP_KERNEL);
 		if (!ca)
 			goto err_close;
 
 		if (register_cache(sb, sb_page, bdev, ca) != 0)
-			goto err;
+			goto err_register;
 	}
 out:
 	if (sb_page)
@@ -2221,6 +2222,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	module_put(THIS_MODULE);
 	return ret;
 
+err_register:
+	kfree(ca);
 err_close:
 	blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
 err:
-- 
2.17.1



                 reply	other threads:[~2018-08-15  7:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180815065006.19856-1-cdbdyx@163.com \
    --to=cdbdyx@163.com \
    --cc=colyli@suse.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®