OSDN Git Service

block/rsxx: add error handling support for add_disk()
authorLuis Chamberlain <mcgrof@kernel.org>
Mon, 27 Sep 2021 22:01:53 +0000 (15:01 -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.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/rsxx/core.c
drivers/block/rsxx/dev.c

index 8363671..8d9d69f 100644 (file)
@@ -935,7 +935,9 @@ static int rsxx_pci_probe(struct pci_dev *dev,
                        card->size8 = 0;
        }
 
-       rsxx_attach_dev(card);
+       st = rsxx_attach_dev(card);
+       if (st)
+               goto failed_create_dev;
 
        /************* Setup Debugfs *************/
        rsxx_debugfs_dev_new(card);
index 2682523..dd33f1b 100644 (file)
@@ -191,6 +191,8 @@ static bool rsxx_discard_supported(struct rsxx_cardinfo *card)
 
 int rsxx_attach_dev(struct rsxx_cardinfo *card)
 {
+       int err = 0;
+
        mutex_lock(&card->dev_lock);
 
        /* The block device requires the stripe size from the config. */
@@ -199,13 +201,17 @@ int rsxx_attach_dev(struct rsxx_cardinfo *card)
                        set_capacity(card->gendisk, card->size8 >> 9);
                else
                        set_capacity(card->gendisk, 0);
-               device_add_disk(CARD_TO_DEV(card), card->gendisk, NULL);
-               card->bdev_attached = 1;
+               err = device_add_disk(CARD_TO_DEV(card), card->gendisk, NULL);
+               if (err == 0)
+                       card->bdev_attached = 1;
        }
 
        mutex_unlock(&card->dev_lock);
 
-       return 0;
+       if (err)
+               blk_cleanup_disk(card->gendisk);
+
+       return err;
 }
 
 void rsxx_detach_dev(struct rsxx_cardinfo *card)