[PATCH v2 1/6] block: refcount the request_queue early in __device_add_disk()

Luis Chamberlain
2021-07-15T04:55:45Z

We refcount the request_queue right now towards the end of the
__device_add_disk(), however when we add error handling on this
function we'll want to refcount the request_queue first, so that
we can simply bail right away on error. No point in doing any
work on the queue if its invalid. Otherwise we'd also be
unwinding all the work we had done towards the very end.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
block/genhd.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index af4d2ab4a633..4dd6db3618f2 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -464,6 +464,15 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
{
int ret;

+ /*
+ * Take an extra ref on queue which will be put on disk_release()
+ * so that it sticks around as long as @disk is there.
+ */
+ if (blk_get_queue(disk->queue))
+ set_bit(GD_QUEUE_REF, &disk->state);
+ else
+ WARN_ON_ONCE(1);
+
/*
* The disk queue should now be all set with enough information about
* the device for the elevator code to pick an adequate default
@@ -528,15 +537,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
if (register_queue)
blk_register_queue(disk);

- /*
- * Take an extra ref on queue which will be put on disk_release()
- * so that it sticks around as long as @disk is there.
- */
- if (blk_get_queue(disk->queue))
- set_bit(GD_QUEUE_REF, &disk->state);
- else
- WARN_ON_ONCE(1);
-
disk_add_events(disk);
blk_integrity_add(disk);
}
--
2.27.0