Commit e32bc729 authored by Dan Williams's avatar Dan Williams

libnvdimm, btt, convert nd_btt_probe() to devm

Pass the device performing the probe so we can use a devm allocation for
the btt superblock.

Cc: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent bd032943
...@@ -314,7 +314,7 @@ static int nd_blk_probe(struct device *dev) ...@@ -314,7 +314,7 @@ static int nd_blk_probe(struct device *dev)
ndns->rw_bytes = nd_blk_rw_bytes; ndns->rw_bytes = nd_blk_rw_bytes;
if (is_nd_btt(dev)) if (is_nd_btt(dev))
rc = nvdimm_namespace_attach_btt(ndns); rc = nvdimm_namespace_attach_btt(ndns);
else if (nd_btt_probe(ndns, blk_dev) == 0) { else if (nd_btt_probe(dev, ndns, blk_dev) == 0) {
/* we'll come back as btt-blk */ /* we'll come back as btt-blk */
rc = -ENXIO; rc = -ENXIO;
} else } else
......
...@@ -1306,7 +1306,7 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize, ...@@ -1306,7 +1306,7 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
struct btt *btt; struct btt *btt;
struct device *dev = &nd_btt->dev; struct device *dev = &nd_btt->dev;
btt = kzalloc(sizeof(struct btt), GFP_KERNEL); btt = devm_kzalloc(dev, sizeof(struct btt), GFP_KERNEL);
if (!btt) if (!btt)
return NULL; return NULL;
...@@ -1321,13 +1321,13 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize, ...@@ -1321,13 +1321,13 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
ret = discover_arenas(btt); ret = discover_arenas(btt);
if (ret) { if (ret) {
dev_err(dev, "init: error in arena_discover: %d\n", ret); dev_err(dev, "init: error in arena_discover: %d\n", ret);
goto out_free; return NULL;
} }
if (btt->init_state != INIT_READY && nd_region->ro) { if (btt->init_state != INIT_READY && nd_region->ro) {
dev_info(dev, "%s is read-only, unable to init btt metadata\n", dev_info(dev, "%s is read-only, unable to init btt metadata\n",
dev_name(&nd_region->dev)); dev_name(&nd_region->dev));
goto out_free; return NULL;
} else if (btt->init_state != INIT_READY) { } else if (btt->init_state != INIT_READY) {
btt->num_arenas = (rawsize / ARENA_MAX_SIZE) + btt->num_arenas = (rawsize / ARENA_MAX_SIZE) +
((rawsize % ARENA_MAX_SIZE) ? 1 : 0); ((rawsize % ARENA_MAX_SIZE) ? 1 : 0);
...@@ -1337,29 +1337,25 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize, ...@@ -1337,29 +1337,25 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
ret = create_arenas(btt); ret = create_arenas(btt);
if (ret) { if (ret) {
dev_info(dev, "init: create_arenas: %d\n", ret); dev_info(dev, "init: create_arenas: %d\n", ret);
goto out_free; return NULL;
} }
ret = btt_meta_init(btt); ret = btt_meta_init(btt);
if (ret) { if (ret) {
dev_err(dev, "init: error in meta_init: %d\n", ret); dev_err(dev, "init: error in meta_init: %d\n", ret);
goto out_free; return NULL;
} }
} }
ret = btt_blk_init(btt); ret = btt_blk_init(btt);
if (ret) { if (ret) {
dev_err(dev, "init: error in blk_init: %d\n", ret); dev_err(dev, "init: error in blk_init: %d\n", ret);
goto out_free; return NULL;
} }
btt_debugfs_init(btt); btt_debugfs_init(btt);
return btt; return btt;
out_free:
kfree(btt);
return NULL;
} }
/** /**
...@@ -1377,7 +1373,6 @@ static void btt_fini(struct btt *btt) ...@@ -1377,7 +1373,6 @@ static void btt_fini(struct btt *btt)
btt_blk_cleanup(btt); btt_blk_cleanup(btt);
free_arenas(btt); free_arenas(btt);
debugfs_remove_recursive(btt->debugfs_dir); debugfs_remove_recursive(btt->debugfs_dir);
kfree(btt);
} }
} }
......
...@@ -273,10 +273,11 @@ static int __nd_btt_probe(struct nd_btt *nd_btt, ...@@ -273,10 +273,11 @@ static int __nd_btt_probe(struct nd_btt *nd_btt,
return 0; return 0;
} }
int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata) int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns,
void *drvdata)
{ {
int rc; int rc;
struct device *dev; struct device *btt_dev;
struct btt_sb *btt_sb; struct btt_sb *btt_sb;
struct nd_region *nd_region = to_nd_region(ndns->dev.parent); struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
...@@ -284,21 +285,20 @@ int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata) ...@@ -284,21 +285,20 @@ int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata)
return -ENODEV; return -ENODEV;
nvdimm_bus_lock(&ndns->dev); nvdimm_bus_lock(&ndns->dev);
dev = __nd_btt_create(nd_region, 0, NULL, ndns); btt_dev = __nd_btt_create(nd_region, 0, NULL, ndns);
nvdimm_bus_unlock(&ndns->dev); nvdimm_bus_unlock(&ndns->dev);
if (!dev) if (!btt_dev)
return -ENOMEM; return -ENOMEM;
dev_set_drvdata(dev, drvdata); dev_set_drvdata(btt_dev, drvdata);
btt_sb = kzalloc(sizeof(*btt_sb), GFP_KERNEL); btt_sb = devm_kzalloc(dev, sizeof(*btt_sb), GFP_KERNEL);
rc = __nd_btt_probe(to_nd_btt(dev), ndns, btt_sb); rc = __nd_btt_probe(to_nd_btt(btt_dev), ndns, btt_sb);
kfree(btt_sb); dev_dbg(dev, "%s: btt: %s\n", __func__,
dev_dbg(&ndns->dev, "%s: btt: %s\n", __func__, rc == 0 ? dev_name(btt_dev) : "<none>");
rc == 0 ? dev_name(dev) : "<none>");
if (rc < 0) { if (rc < 0) {
struct nd_btt *nd_btt = to_nd_btt(dev); struct nd_btt *nd_btt = to_nd_btt(btt_dev);
__nd_detach_ndns(dev, &nd_btt->ndns); __nd_detach_ndns(btt_dev, &nd_btt->ndns);
put_device(dev); put_device(btt_dev);
} }
return rc; return rc;
......
...@@ -197,11 +197,13 @@ struct nd_gen_sb { ...@@ -197,11 +197,13 @@ struct nd_gen_sb {
u64 nd_sb_checksum(struct nd_gen_sb *sb); u64 nd_sb_checksum(struct nd_gen_sb *sb);
#if IS_ENABLED(CONFIG_BTT) #if IS_ENABLED(CONFIG_BTT)
int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata); int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns,
void *drvdata);
bool is_nd_btt(struct device *dev); bool is_nd_btt(struct device *dev);
struct device *nd_btt_create(struct nd_region *nd_region); struct device *nd_btt_create(struct nd_region *nd_region);
#else #else
static inline int nd_btt_probe(struct nd_namespace_common *ndns, void *drvdata) static inline int nd_btt_probe(struct device *dev,
struct nd_namespace_common *ndns, void *drvdata)
{ {
return -ENODEV; return -ENODEV;
} }
......
...@@ -574,7 +574,7 @@ static int nd_pmem_probe(struct device *dev) ...@@ -574,7 +574,7 @@ static int nd_pmem_probe(struct device *dev)
if (is_nd_pfn(dev)) if (is_nd_pfn(dev))
return nvdimm_namespace_attach_pfn(ndns); return nvdimm_namespace_attach_pfn(ndns);
if (nd_btt_probe(ndns, pmem) == 0 if (nd_btt_probe(dev, ndns, pmem) == 0
|| nd_pfn_probe(dev, ndns, pmem) == 0) { || nd_pfn_probe(dev, ndns, pmem) == 0) {
/* /*
* We'll come back as either btt-pmem, or pfn-pmem, so * We'll come back as either btt-pmem, or pfn-pmem, so
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment