md: add error handling support for add_disk()
authorLuis Chamberlain <mcgrof@kernel.org>
Wed, 1 Sep 2021 11:38:30 +0000 (13:38 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 20:50:10 +0000 (14:50 -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.

We just do the unwinding of what was not done before, and are
sure to unlock prior to bailing.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/md.c

index 22310d5..eff3d23 100644 (file)
@@ -5700,7 +5700,11 @@ static int md_alloc(dev_t dev, char *name)
        disk->flags |= GENHD_FL_EXT_DEVT;
        disk->events |= DISK_EVENT_MEDIA_CHANGE;
        mddev->gendisk = disk;
-       add_disk(disk);
+       error = add_disk(disk);
+       if (error) {
+               blk_cleanup_disk(disk);
+               goto abort;
+       }
 
        error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
        if (error) {