@@ -32,9 +32,9 @@ struct dev_dax *__dax_pmem_probe(struct device *dev, enum dev_dax_subsys subsys)
if (rc)
return ERR_PTR(rc);
rc = nvdimm_setup_pfn(nd_pfn, &pgmap);
+ devm_namespace_disable(dev, ndns);
if (rc)
return ERR_PTR(rc);
- devm_namespace_disable(dev, ndns);
/* reserve the metadata area, device-dax will reserve the data */
pfn_sb = nd_pfn->pfn_sb;
@@ -1695,13 +1695,16 @@ int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns)
dev_dbg(&nd_btt->dev, "%s must be at least %ld bytes\n",
dev_name(&ndns->dev),
ARENA_MIN_SIZE + nd_btt->initial_offset);
+ devm_namespace_disable(&nd_btt->dev, ndns);
return -ENXIO;
}
nd_region = to_nd_region(nd_btt->dev.parent);
btt = btt_init(nd_btt, rawsize, nd_btt->lbasize, nd_btt->uuid,
nd_region);
- if (!btt)
+ if (!btt) {
+ devm_namespace_disable(&nd_btt->dev, ndns);
return -ENOMEM;
+ }
nd_btt->btt = btt;
return 0;
@@ -318,13 +318,18 @@ int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio,
}
ndns->rw_bytes = nsio_rw_bytes;
- if (devm_init_badblocks(dev, &nsio->bb))
+ if (devm_init_badblocks(dev, &nsio->bb)) {
+ devm_release_mem_region(dev, range.start, size);
return -ENOMEM;
+ }
nvdimm_badblocks_populate(to_nd_region(ndns->dev.parent), &nsio->bb,
&range);
nsio->addr = devm_memremap(dev, range.start, size, ARCH_MEMREMAP_PMEM);
-
+ if (IS_ERR(nsio->addr)) {
+ devm_exit_badblocks(dev, &nsio->bb);
+ devm_release_mem_region(dev, range.start, size);
+ }
return PTR_ERR_OR_ZERO(nsio->addr);
}
@@ -416,8 +416,10 @@ static int pmem_attach_disk(struct device *dev,
if (is_nd_pfn(dev)) {
nd_pfn = to_nd_pfn(dev);
rc = nvdimm_setup_pfn(nd_pfn, &pmem->pgmap);
- if (rc)
+ if (rc) {
+ devm_namespace_disable(dev, ndns);
return rc;
+ }
}
/* we're attaching a block device, disable raw namespace access */
@@ -564,17 +566,15 @@ static int nd_pmem_probe(struct device *dev)
ret = nd_pfn_probe(dev, ndns);
if (ret == 0)
return -ENXIO;
- else if (ret == -EOPNOTSUPP)
- return ret;
-
- ret = nd_dax_probe(dev, ndns);
- if (ret == 0)
- return -ENXIO;
- else if (ret == -EOPNOTSUPP)
- return ret;
-
+ else if (ret != -EOPNOTSUPP) {
+ ret = nd_dax_probe(dev, ndns);
+ if (ret == 0)
+ return -ENXIO;
+ }
/* probe complete, attach handles namespace enabling */
devm_namespace_disable(dev, ndns);
+ if (ret == -EOPNOTSUPP)
+ return ret;
return pmem_attach_disk(dev, ndns);
}