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@xxxxxxx> --- 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