From: Dan Williams <dan.j.williams@intel.com>
Date: Mon, 2 Apr 2018 13:14:25 -0700
Subject: libnvdimm: add an api to cast a 'struct nd_region' to its 'struct
device'
Patch-mainline: v4.17-rc1
Git-commit: 243f29fe449bbead69076ad861dbe8f51b42c4d7
References: bsc#1094119
For debug, it is useful for bus providers to be able to retrieve the
'struct device' associated with an nd_region instance that it
registered. We already have to_nd_region() to perform the reverse cast
operation, in fact its duplicate declaration can be removed from the
private drivers/nvdimm/nd.h header.
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/nvdimm/nd.h | 1 -
drivers/nvdimm/region_devs.c | 8 ++++++++
include/linux/libnvdimm.h | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -339,7 +339,6 @@ static inline struct device *nd_dax_crea
}
#endif
-struct nd_region *to_nd_region(struct device *dev);
int nd_region_to_nstype(struct nd_region *nd_region);
int nd_region_register_namespaces(struct nd_region *nd_region, int *err);
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -178,6 +178,14 @@ struct nd_region *to_nd_region(struct de
}
EXPORT_SYMBOL_GPL(to_nd_region);
+struct device *nd_region_dev(struct nd_region *nd_region)
+{
+ if (!nd_region)
+ return NULL;
+ return &nd_region->dev;
+}
+EXPORT_SYMBOL_GPL(nd_region_dev);
+
struct nd_blk_region *to_nd_blk_region(struct device *dev)
{
struct nd_region *nd_region = to_nd_region(dev);
--- a/include/linux/libnvdimm.h
+++ b/include/linux/libnvdimm.h
@@ -148,6 +148,7 @@ void nvdimm_bus_unregister(struct nvdimm
struct nvdimm_bus *to_nvdimm_bus(struct device *dev);
struct nvdimm *to_nvdimm(struct device *dev);
struct nd_region *to_nd_region(struct device *dev);
+struct device *nd_region_dev(struct nd_region *nd_region);
struct nd_blk_region *to_nd_blk_region(struct device *dev);
struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus);