nullblk: Fix cleanup order in null_add_dev() error path
authorDamien Le Moal <dlemoal@kernel.org>
Sat, 30 Mar 2024 00:53:00 +0000 (09:53 +0900)
committerJens Axboe <axboe@kernel.dk>
Tue, 2 Apr 2024 13:43:24 +0000 (07:43 -0600)
In null_add_dev(), if an error happen after initializing the resources
for a zoned null block device, we must free these resources before
exiting the function. To ensure this, move the out_cleanup_zone label
after out_cleanup_disk as we jump to this latter label if an error
happens after calling null_init_zoned_dev().

Fixes: e440626b1caf ("null_blk: pass queue_limits to blk_mq_alloc_disk")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240330005300.1503252-1-dlemoal@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/null_blk/main.c

index 71c39bcd872c7ecaabc67e91f35aa2fb267d6826..ed33cf7192d21672fb389a93c20fbbb887796337 100644 (file)
@@ -1965,10 +1965,10 @@ static int null_add_dev(struct nullb_device *dev)
 
 out_ida_free:
        ida_free(&nullb_indexes, nullb->index);
-out_cleanup_zone:
-       null_free_zoned_dev(dev);
 out_cleanup_disk:
        put_disk(nullb->disk);
+out_cleanup_zone:
+       null_free_zoned_dev(dev);
 out_cleanup_tags:
        if (nullb->tag_set == &nullb->__tag_set)
                blk_mq_free_tag_set(nullb->tag_set);