loop: add error handling support for add_disk()
authorLuis Chamberlain <mcgrof@kernel.org>
Mon, 27 Sep 2021 21:59:57 +0000 (14:59 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 20:41:36 +0000 (14:41 -0600)
We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c

index 7bf4686..00ee365 100644 (file)
@@ -2394,13 +2394,19 @@ static int loop_add(int i)
        disk->event_flags       = DISK_EVENT_FLAG_UEVENT;
        sprintf(disk->disk_name, "loop%d", i);
        /* Make this loop device reachable from pathname. */
-       add_disk(disk);
+       err = add_disk(disk);
+       if (err)
+               goto out_cleanup_disk;
+
        /* Show this loop device. */
        mutex_lock(&loop_ctl_mutex);
        lo->idr_visible = true;
        mutex_unlock(&loop_ctl_mutex);
+
        return i;
 
+out_cleanup_disk:
+       blk_cleanup_disk(disk);
 out_cleanup_tags:
        blk_mq_free_tag_set(&lo->tag_set);
 out_free_idr: