[SRU][Zesty][v2][PATCH 1/2] bcache: Fix leak of bdev reference

Joseph Salisbury joseph.salisbury at canonical.com
Mon Dec 11 14:20:32 UTC 2017

From: Jan Kara <jack at suse.cz>

BugLink: http://bugs.launchpad.net/bugs/1729145

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 at suse.cz>
Acked-by: Coly Li <colyli at suse.de>
Cc: stable at vger.kernel.org
Signed-off-by: Jens Axboe <axboe at kernel.dk>
(cherry picked from commit 4b758df21ee7081ab41448d21d60367efaa625b3)
Signed-off-by: Joseph Salisbury <joseph.salisbury at canonical.com>
 drivers/md/bcache/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 1809606..fc8613b 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1965,6 +1965,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 				err = "device busy";
+			if (!IS_ERR(bdev))
+				bdput(bdev);
 			if (attr == &ksysfs_register_quiet)
 				goto out;

More information about the kernel-team mailing list