From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@ml01.01.org
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 03/13] libnvdimm, pfn, convert nd_pfn_probe() to devm
Date: Wed, 23 Mar 2016 18:25:37 -0700 [thread overview]
Message-ID: <20160324012537.21436.22245.stgit@dwillia2-desk3.jf.intel.com> (raw)
In-Reply-To: <20160324012520.21436.22505.stgit@dwillia2-desk3.jf.intel.com>
Pass the device performing the probe so we can use a devm allocation for
the pfn superblock.
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
drivers/nvdimm/nd.h | 6 ++++--
drivers/nvdimm/pfn_devs.c | 27 +++++++++++++--------------
drivers/nvdimm/pmem.c | 30 +++++++++---------------------
3 files changed, 26 insertions(+), 37 deletions(-)
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index b0a4ab91307b..c831caa3d60a 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -219,12 +219,14 @@ static inline struct device *nd_btt_create(struct nd_region *nd_region)
struct nd_pfn *to_nd_pfn(struct device *dev);
#if IS_ENABLED(CONFIG_NVDIMM_PFN)
-int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata);
+int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns,
+ void *drvdata);
bool is_nd_pfn(struct device *dev);
struct device *nd_pfn_create(struct nd_region *nd_region);
int nd_pfn_validate(struct nd_pfn *nd_pfn);
#else
-static inline int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata)
+static inline int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns,
+ void *drvdata)
{
return -ENODEV;
}
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index 254d3bc13f70..63e2df3e052c 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -410,11 +410,12 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn)
}
EXPORT_SYMBOL(nd_pfn_validate);
-int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata)
+int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns,
+ void *drvdata)
{
int rc;
- struct device *dev;
struct nd_pfn *nd_pfn;
+ struct device *pfn_dev;
struct nd_pfn_sb *pfn_sb;
struct nd_region *nd_region = to_nd_region(ndns->dev.parent);
@@ -422,24 +423,22 @@ int nd_pfn_probe(struct nd_namespace_common *ndns, void *drvdata)
return -ENODEV;
nvdimm_bus_lock(&ndns->dev);
- dev = __nd_pfn_create(nd_region, ndns);
+ pfn_dev = __nd_pfn_create(nd_region, ndns);
nvdimm_bus_unlock(&ndns->dev);
- if (!dev)
+ if (!pfn_dev)
return -ENOMEM;
- dev_set_drvdata(dev, drvdata);
- pfn_sb = kzalloc(sizeof(*pfn_sb), GFP_KERNEL);
- nd_pfn = to_nd_pfn(dev);
+ dev_set_drvdata(pfn_dev, drvdata);
+ pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
+ nd_pfn = to_nd_pfn(pfn_dev);
nd_pfn->pfn_sb = pfn_sb;
rc = nd_pfn_validate(nd_pfn);
- nd_pfn->pfn_sb = NULL;
- kfree(pfn_sb);
- dev_dbg(&ndns->dev, "%s: pfn: %s\n", __func__,
- rc == 0 ? dev_name(dev) : "<none>");
+ dev_dbg(dev, "%s: pfn: %s\n", __func__,
+ rc == 0 ? dev_name(pfn_dev) : "<none>");
if (rc < 0) {
- __nd_detach_ndns(dev, &nd_pfn->ndns);
- put_device(dev);
+ __nd_detach_ndns(pfn_dev, &nd_pfn->ndns);
+ put_device(pfn_dev);
} else
- __nd_device_register(&nd_pfn->dev);
+ __nd_device_register(pfn_dev);
return rc;
}
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index b13b9095f620..77d94b42c32f 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -316,18 +316,19 @@ static int pmem_rw_bytes(struct nd_namespace_common *ndns,
static int nd_pfn_init(struct nd_pfn *nd_pfn)
{
- struct nd_pfn_sb *pfn_sb = kzalloc(sizeof(*pfn_sb), GFP_KERNEL);
struct pmem_device *pmem = dev_get_drvdata(&nd_pfn->dev);
struct nd_namespace_common *ndns = nd_pfn->ndns;
u32 start_pad = 0, end_trunc = 0;
resource_size_t start, size;
struct nd_namespace_io *nsio;
struct nd_region *nd_region;
+ struct nd_pfn_sb *pfn_sb;
unsigned long npfns;
phys_addr_t offset;
u64 checksum;
int rc;
+ pfn_sb = devm_kzalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL);
if (!pfn_sb)
return -ENOMEM;
@@ -343,7 +344,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
dev_info(&nd_pfn->dev,
"%s is read-only, unable to init metadata\n",
dev_name(&nd_region->dev));
- goto err;
+ return -ENXIO;
}
memset(pfn_sb, 0, sizeof(*pfn_sb));
@@ -388,12 +389,12 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
else if (nd_pfn->mode == PFN_MODE_RAM)
offset = ALIGN(start + SZ_8K, nd_pfn->align) - start;
else
- goto err;
+ return -ENXIO;
if (offset + start_pad + end_trunc >= pmem->size) {
dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n",
dev_name(&ndns->dev));
- goto err;
+ return -ENXIO;
}
npfns = (pmem->size - offset - start_pad - end_trunc) / SZ_4K;
@@ -410,30 +411,16 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
pfn_sb->checksum = cpu_to_le64(checksum);
- rc = nvdimm_write_bytes(ndns, SZ_4K, pfn_sb, sizeof(*pfn_sb));
- if (rc)
- goto err;
-
- return 0;
- err:
- nd_pfn->pfn_sb = NULL;
- kfree(pfn_sb);
- return -ENXIO;
+ return nvdimm_write_bytes(ndns, SZ_4K, pfn_sb, sizeof(*pfn_sb));
}
-static int nvdimm_namespace_detach_pfn(struct nd_pfn *nd_pfn)
+static void nvdimm_namespace_detach_pfn(struct nd_pfn *nd_pfn)
{
struct pmem_device *pmem;
/* free pmem disk */
pmem = dev_get_drvdata(&nd_pfn->dev);
pmem_detach_disk(pmem);
-
- /* release nd_pfn resources */
- kfree(nd_pfn->pfn_sb);
- nd_pfn->pfn_sb = NULL;
-
- return 0;
}
/*
@@ -573,7 +560,8 @@ static int nd_pmem_probe(struct device *dev)
if (is_nd_pfn(dev))
return nvdimm_namespace_attach_pfn(ndns);
- if (nd_btt_probe(ndns, pmem) == 0 || nd_pfn_probe(ndns, pmem) == 0) {
+ if (nd_btt_probe(ndns, pmem) == 0
+ || nd_pfn_probe(dev, ndns, pmem) == 0) {
/*
* We'll come back as either btt-pmem, or pfn-pmem, so
* drop the queue allocation for now.
next prev parent reply other threads:[~2016-03-24 1:26 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-24 1:25 [PATCH 00/13] prep for device-dax, untangle pfn-device setup Dan Williams
2016-03-24 1:25 ` [PATCH 01/13] libnvdimm, pfn: fix nvdimm_namespace_add_poison() vs section alignment Dan Williams
2016-03-24 10:10 ` Johannes Thumshirn
2016-03-24 14:48 ` Dan Williams
2016-03-24 1:25 ` [PATCH 02/13] libnvdimm, pmem: kill pmem->ndns Dan Williams
2016-03-24 10:31 ` Johannes Thumshirn
2016-03-24 1:25 ` Dan Williams [this message]
2016-03-24 10:45 ` [PATCH 03/13] libnvdimm, pfn, convert nd_pfn_probe() to devm Johannes Thumshirn
2016-03-24 1:25 ` [PATCH 04/13] libnvdimm, btt, convert nd_btt_probe() " Dan Williams
2016-03-24 11:05 ` Johannes Thumshirn
2016-03-24 1:25 ` [PATCH 05/13] libnvdimm, blk: use devm_add_action to release bdev resources Dan Williams
2016-03-24 11:48 ` Johannes Thumshirn
2016-03-24 15:14 ` Dan Williams
2016-03-24 15:15 ` Johannes Thumshirn
2016-03-24 15:21 ` Dan Williams
2016-03-24 1:25 ` [PATCH 06/13] libnvdimm, blk: use ->queuedata for driver private data Dan Williams
2016-03-24 11:51 ` Johannes Thumshirn
2016-03-24 1:25 ` [PATCH 07/13] libnvdimm, pmem: " Dan Williams
2016-03-24 12:06 ` Johannes Thumshirn
2016-03-24 1:26 ` [PATCH 08/13] libnvdimm, blk: move i/o infrastructure to nd_namespace_blk Dan Williams
2016-03-24 12:22 ` Johannes Thumshirn
2016-03-24 15:21 ` Dan Williams
2016-03-24 15:22 ` Johannes Thumshirn
2016-03-25 22:02 ` [PATCH v2] " Dan Williams
2016-03-24 1:26 ` [PATCH 09/13] libnvdimm, pmem: use devm_add_action to release bdev resources Dan Williams
2016-03-24 12:35 ` Johannes Thumshirn
2016-03-24 1:26 ` [PATCH 10/13] libnvdimm, pmem: clean up resource print / request Dan Williams
2016-03-24 13:42 ` Johannes Thumshirn
2016-03-24 1:26 ` [PATCH 11/13] libnvdimm, pmem, pfn: make pmem_rw_bytes generic and refactor pfn setup Dan Williams
2016-03-24 13:50 ` Johannes Thumshirn
2016-03-25 22:13 ` [PATCH v2] " Dan Williams
2016-03-24 1:26 ` [PATCH 12/13] libnvdimm, pmem, pfn: move pfn setup to the core Dan Williams
2016-03-24 14:36 ` Johannes Thumshirn
2016-03-24 15:26 ` Dan Williams
2016-03-25 22:15 ` [PATCH v2] " Dan Williams
2016-03-29 8:30 ` Johannes Thumshirn
2016-03-24 1:26 ` [PATCH 13/13] libnvdimm, pmem: kill ->pmem_queue and ->pmem_disk Dan Williams
2016-03-24 14:38 ` Johannes Thumshirn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160324012537.21436.22245.stgit@dwillia2-desk3.jf.intel.com \
--to=dan.j.williams@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@ml01.01.org \
--cc=ross.zwisler@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®