* [PATCH 2/2] fix potential memory leak in function "register_bcache"
@ 2018-08-15 6:50 Dongbo Cao
0 siblings, 0 replies; only message in thread
From: Dongbo Cao @ 2018-08-15 6:50 UTC (permalink / raw)
To: colyli; +Cc: kent.overstreet, linux-bcache, linux-kernel, Dongbo Cao
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-08-15 7:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 6:50 [PATCH 2/2] fix potential memory leak in function "register_bcache" Dongbo Cao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).