@@ -505,7 +505,9 @@ static int pmem_attach_disk(struct device *dev,
dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
pmem->dax_dev = dax_dev;
- device_add_disk(dev, disk, pmem_attribute_groups);
+ rc = device_add_disk(dev, disk, pmem_attribute_groups);
+ if (rc)
+ goto out_cleanup_dax;
if (devm_add_action_or_reset(dev, pmem_release_disk, pmem))
return -ENOMEM;
@@ -516,6 +518,10 @@ static int pmem_attach_disk(struct device *dev,
if (!pmem->bb_state)
dev_warn(dev, "'badblocks' notification disabled\n");
return 0;
+
+out_cleanup_dax:
+ kill_dax(pmem->dax_dev);
+ put_dax(pmem->dax_dev);
out:
blk_cleanup_disk(pmem->disk);
return rc;