Blob Blame History Raw
From 15c30104965101b8e76b24d27035569d6613a7d6 Mon Sep 17 00:00:00 2001
From: Yu Kuai <yukuai3@huawei.com>
Date: Tue, 2 Nov 2021 10:07:05 +0800
Subject: [PATCH] blk-cgroup: fix missing put device in error path from
 blkg_conf_pref()
Git-commit: 15c30104965101b8e76b24d27035569d6613a7d6
Patch-mainline: v5.16-rc2
References: bsc#1195481

If blk_queue_enter() failed due to queue is dying, the
blkdev_put_no_open() is needed because blkcg_conf_open_bdev() succeeded.

Fixes: 0c9d338c8443 ("blk-cgroup: synchronize blkg creation against policy deactivation")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20211102020705.2321858-1-yukuai3@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Acked-by: Jan Kara <jack@suse.cz>

---
 block/blk-cgroup.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -617,7 +617,7 @@ int blkg_conf_prep(struct blkcg *blkcg,
 	 */
 	ret = blk_queue_enter(q, 0);
 	if (ret)
-		return ret;
+		goto fail;
 
 	rcu_read_lock();
 	spin_lock_irq(&q->queue_lock);
@@ -653,7 +653,7 @@ int blkg_conf_prep(struct blkcg *blkcg,
 		new_blkg = blkg_alloc(pos, q, GFP_KERNEL);
 		if (unlikely(!new_blkg)) {
 			ret = -ENOMEM;
-			goto fail;
+			goto fail_exit_queue;
 		}
 
 		rcu_read_lock();
@@ -688,8 +688,9 @@ success:
 fail_unlock:
 	spin_unlock_irq(&q->queue_lock);
 	rcu_read_unlock();
-fail:
+fail_exit_queue:
 	blk_queue_exit(q);
+fail:
 	put_disk_and_module(disk);
 	/*
 	 * If queue was bypassing, we should retry.  Do so after a