libnvdimm: use devm_add_action_or_reset()
authorDan Williams <dan.j.williams@intel.com>
Wed, 15 Jun 2016 21:59:17 +0000 (14:59 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 15 Jun 2016 21:59:17 +0000 (14:59 -0700)
Clean up needless calls to the action routine by letting
devm_add_action_or_reset() call it automatically.  This does cause the
disk to registered and immediately unregistered when a memory allocation
fails, but the block layer should be prepared for such an event.

Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/blk.c
drivers/nvdimm/pmem.c

index 495e06d9f7e7f39013d910e4459720b61ebd90f5..dfe691cf4d743986fade7f6b61c719aaa3c8c5ae 100644 (file)
@@ -267,10 +267,8 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        q = blk_alloc_queue(GFP_KERNEL);
        if (!q)
                return -ENOMEM;
-       if (devm_add_action(dev, nd_blk_release_queue, q)) {
-               blk_cleanup_queue(q);
+       if (devm_add_action_or_reset(dev, nd_blk_release_queue, q))
                return -ENOMEM;
-       }
 
        blk_queue_make_request(q, nd_blk_make_request);
        blk_queue_max_hw_sectors(q, UINT_MAX);
@@ -282,10 +280,6 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        disk = alloc_disk(0);
        if (!disk)
                return -ENOMEM;
-       if (devm_add_action(dev, nd_blk_release_disk, disk)) {
-               put_disk(disk);
-               return -ENOMEM;
-       }
 
        disk->driverfs_dev      = dev;
        disk->first_minor       = 0;
@@ -296,6 +290,9 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        set_capacity(disk, 0);
        add_disk(disk);
 
+       if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk))
+               return -ENOMEM;
+
        if (nsblk_meta_size(nsblk)) {
                int rc = nd_integrity_init(disk, nsblk_meta_size(nsblk));
 
index 608fc4464574e1d9edb4037c53b6998afdb11ebe..ba253df6233f9339f38016219abe0ec12ac34177 100644 (file)
@@ -195,7 +195,7 @@ static void pmem_release_queue(void *q)
        blk_cleanup_queue(q);
 }
 
-void pmem_release_disk(void *disk)
+static void pmem_release_disk(void *disk)
 {
        del_gendisk(disk);
        put_disk(disk);
@@ -269,10 +269,8 @@ static int pmem_attach_disk(struct device *dev,
         * At release time the queue must be dead before
         * devm_memremap_pages is unwound
         */
-       if (devm_add_action(dev, pmem_release_queue, q)) {
-               blk_cleanup_queue(q);
+       if (devm_add_action_or_reset(dev, pmem_release_queue, q))
                return -ENOMEM;
-       }
 
        if (IS_ERR(addr))
                return PTR_ERR(addr);
@@ -288,10 +286,6 @@ static int pmem_attach_disk(struct device *dev,
        disk = alloc_disk_node(0, nid);
        if (!disk)
                return -ENOMEM;
-       if (devm_add_action(dev, pmem_release_disk, disk)) {
-               put_disk(disk);
-               return -ENOMEM;
-       }
 
        disk->fops              = &pmem_fops;
        disk->queue             = q;
@@ -305,6 +299,10 @@ static int pmem_attach_disk(struct device *dev,
        nvdimm_badblocks_populate(to_nd_region(dev->parent), &pmem->bb, res);
        disk->bb = &pmem->bb;
        add_disk(disk);
+
+       if (devm_add_action_or_reset(dev, pmem_release_disk, disk))
+               return -ENOMEM;
+
        revalidate_disk(disk);
 
        return 0;