blkcg: fix gendisk reference leak in blkg_conf_prep()

This change “blkcg: fix gendisk reference leak in blkg_conf_prep()” (commit 5f6c2d2) in Linux kernel is authored by Tejun Heo <tj [at] kernel.org> on Wed Jul 22 18:05:53 2015 -0400.

Description of "blkcg: fix gendisk reference leak in blkg_conf_prep()"

The change “blkcg: fix gendisk reference leak in blkg_conf_prep()” introduces changes as follows.

blkcg: fix gendisk reference leak in blkg_conf_prep()

When a blkcg configuration is targeted to a partition rather than a
whole device, blkg_conf_prep fails with -EINVAL; unfortunately, it
forgets to put the gendisk ref in that case.  Fix it.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@fb.com>

Linux kernel releases containing commit 5f6c2d2

Linux kernel code changes from "blkcg: fix gendisk reference leak in blkg_conf_prep()"

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 block/blk-cgroup.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
 
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 9da02c021ebe..d6283b3f5db5 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -718,8 +718,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
 		return -EINVAL;
 
 	disk = get_gendisk(MKDEV(major, minor), &part);
-	if (!disk || part)
+	if (!disk)
 		return -EINVAL;
+	if (part) {
+		put_disk(disk);
+		return -EINVAL;
+	}
 
 	rcu_read_lock();
 	spin_lock_irq(disk->queue->queue_lock);

The commit for this change in Linux stable tree is 5f6c2d2 (patch).

Last modified: 2020/02/09