Skip to contentSkip to conversation

bcache: Fix leak of bdev reference

PATCH In review Jan Kara 1 participant 2 messages Feb 9, 2017 – Mar 7, 2017 bcache (block layer cache)

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 bcache: Fix leak of bdev reference

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.

---
 drivers/md/bcache/super.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/bcache/super.c +2 -0
index 3a19cbc8b230..2a6a4a0520f6 100644
@@ -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);
+			if (!IS_ERR(bdev))
+				bdput(bdev);
 			if (attr == &ksysfs_register_quiet)
 				goto out;
 		}
Signature · 1 line
2.10.2
author
#1 lore raw
Quoted 6 lines · Jan Kara

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.

Ping? This seems to have fallen through the cracks...

Honza

Quoted 20 lines
---
 drivers/md/bcache/super.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/bcache/super.c +2 -0
index 3a19cbc8b230..2a6a4a0520f6 100644
@@ -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);
+			if (!IS_ERR(bdev))
+				bdput(bdev);
 			if (attr == &ksysfs_register_quiet)
 				goto out;
 		}
Signature · 1 line
2.10.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR