bcache: Fix leak of bdev reference
authorJan Kara <jack@suse.cz>
Wed, 6 Sep 2017 06:25:51 +0000 (14:25 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 6 Sep 2017 14:17:33 +0000 (08:17 -0600)
If blkdev_get_by_path() in register_bcache() fails, we try to lookup the
block device using lookup_bdev() to detect which situation we are in to
properly report error. However we never drop the reference returned to
us from lookup_bdev(). Fix that.

Signed-off-by: Jan Kara <jack@suse.cz>
Acked-by: Coly Li <colyli@suse.de>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/super.c

index 974d832e54a62635c08b21c98a72fe25963b09a6..c3fedd265d184b2408de14ce5fd7d83653026c07 100644 (file)
@@ -1964,6 +1964,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
                        else
                                err = "device busy";
                        mutex_unlock(&bch_register_lock);
                        else
                                err = "device busy";
                        mutex_unlock(&bch_register_lock);
+                       if (!IS_ERR(bdev))
+                               bdput(bdev);
                        if (attr == &ksysfs_register_quiet)
                                goto out;
                }
                        if (attr == &ksysfs_register_quiet)
                                goto out;
                }