nvdimm/blk: add error handling support for add_disk()
authorLuis Chamberlain <mcgrof@kernel.org>
Wed, 3 Nov 2021 23:04:27 +0000 (16:04 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 4 Nov 2021 11:48:49 +0000 (05:48 -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.

Since nvdimm/blk uses devm we just need to move the devm
registration towards the end. And in hindsight, that seems
to also provide a fix given del_gendisk() should not be
called unless the disk was already added via add_disk().
The probably of that issue happening is low though, like
OOM while calling devm_add_action(), so the fix is minor.

We manually unwind in case of add_disk() failure prior
to the devm registration.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20211103230437.1639990-5-mcgrof@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvdimm/blk.c

index 4eef67918a7edaae1657fa56517439a8a193bed8..228c33b8d1d69793ef5398f417c51ba6166f4f3c 100644 (file)
@@ -264,7 +264,9 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        }
 
        set_capacity(disk, available_disk_size >> SECTOR_SHIFT);
-       device_add_disk(dev, disk, NULL);
+       rc = device_add_disk(dev, disk, NULL);
+       if (rc)
+               goto out_before_devm_err;
 
        /* nd_blk_release_disk() is called if this fails */
        if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk))