Skip to content

Commit 5a192cc

Browse files
mcgrofaxboe
authored andcommitted
nvdimm/pmem: use add_disk() error handling
Now that device_add_disk() supports returning an error, use that. We must unwind alloc_dax() on error. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent accf58a commit 5a192cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/nvdimm/pmem.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ static int pmem_attach_disk(struct device *dev,
491491
dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
492492
pmem->dax_dev = dax_dev;
493493

494-
device_add_disk(dev, disk, pmem_attribute_groups);
494+
rc = device_add_disk(dev, disk, pmem_attribute_groups);
495+
if (rc)
496+
goto out_cleanup_dax;
495497
if (devm_add_action_or_reset(dev, pmem_release_disk, pmem))
496498
return -ENOMEM;
497499

@@ -502,6 +504,10 @@ static int pmem_attach_disk(struct device *dev,
502504
if (!pmem->bb_state)
503505
dev_warn(dev, "'badblocks' notification disabled\n");
504506
return 0;
507+
508+
out_cleanup_dax:
509+
kill_dax(pmem->dax_dev);
510+
put_dax(pmem->dax_dev);
505511
out:
506512
blk_cleanup_disk(pmem->disk);
507513
return rc;

0 commit comments

Comments
 (0)