dax: use devm_add_action_or_reset()
authorSajjan, Vikas C <vikas.cha.sajjan@hpe.com>
Tue, 5 Jul 2016 05:50:07 +0000 (11:20 +0530)
committerDan Williams <dan.j.williams@intel.com>
Wed, 6 Jul 2016 22:14:48 +0000 (15:14 -0700)
If devm_add_action() fails, we are explicitly calling the cleanup to free
the resources allocated. Use the helper devm_add_action_or_reset()
and return directly in case of error, since the cleanup function
has been already called by the helper if there was any error.

Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Vikas C Sajjan <vikas.cha.sajjan@hpe.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/dax/dax.c
drivers/dax/pmem.c

index b891a12..803f395 100644 (file)
@@ -211,11 +211,9 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res,
        }
        dax_dev->dev = dev;
 
-       rc = devm_add_action(dax_region->dev, unregister_dax_dev, dev);
-       if (rc) {
-               unregister_dax_dev(dev);
+       rc = devm_add_action_or_reset(dax_region->dev, unregister_dax_dev, dev);
+       if (rc)
                return rc;
-       }
 
        return 0;
 
index 55d510e..dfb1685 100644 (file)
@@ -102,21 +102,19 @@ static int dax_pmem_probe(struct device *dev)
        if (rc)
                return rc;
 
-       rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
-       if (rc) {
-               dax_pmem_percpu_exit(&dax_pmem->ref);
+       rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
+                                                       &dax_pmem->ref);
+       if (rc)
                return rc;
-       }
 
        addr = devm_memremap_pages(dev, &res, &dax_pmem->ref, altmap);
        if (IS_ERR(addr))
                return PTR_ERR(addr);
 
-       rc = devm_add_action(dev, dax_pmem_percpu_kill, &dax_pmem->ref);
-       if (rc) {
-               dax_pmem_percpu_kill(&dax_pmem->ref);
+       rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
+                                                       &dax_pmem->ref);
+       if (rc)
                return rc;
-       }
 
        nd_region = to_nd_region(dev->parent);
        dax_region = alloc_dax_region(dev, nd_region->id, &res,