Commit d76911ee authored by Dan Williams's avatar Dan Williams

dax: convert devm_create_dax_dev to PTR_ERR

For sub-division support we need access to the dax_dev created by
devm_create_dax_dev().
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 9d2d01a0
...@@ -558,8 +558,8 @@ static void unregister_dax_dev(void *dev) ...@@ -558,8 +558,8 @@ static void unregister_dax_dev(void *dev)
device_unregister(dev); device_unregister(dev);
} }
int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region,
int count) struct resource *res, int count)
{ {
struct device *parent = dax_region->dev; struct device *parent = dax_region->dev;
struct dax_dev *dax_dev; struct dax_dev *dax_dev;
...@@ -570,7 +570,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, ...@@ -570,7 +570,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res,
dax_dev = kzalloc(sizeof(*dax_dev) + sizeof(*res) * count, GFP_KERNEL); dax_dev = kzalloc(sizeof(*dax_dev) + sizeof(*res) * count, GFP_KERNEL);
if (!dax_dev) if (!dax_dev)
return -ENOMEM; return ERR_PTR(-ENOMEM);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (!IS_ALIGNED(res[i].start, dax_region->align) if (!IS_ALIGNED(res[i].start, dax_region->align)
...@@ -632,10 +632,14 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, ...@@ -632,10 +632,14 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res,
rc = device_add(dev); rc = device_add(dev);
if (rc) { if (rc) {
put_device(dev); put_device(dev);
return rc; return ERR_PTR(rc);
} }
return devm_add_action_or_reset(dax_region->dev, unregister_dax_dev, dev); rc = devm_add_action_or_reset(dax_region->dev, unregister_dax_dev, dev);
if (rc)
return ERR_PTR(rc);
return dax_dev;
err_cdev: err_cdev:
iput(dax_dev->inode); iput(dax_dev->inode);
...@@ -646,7 +650,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, ...@@ -646,7 +650,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res,
err_id: err_id:
kfree(dax_dev); kfree(dax_dev);
return rc; return ERR_PTR(rc);
} }
EXPORT_SYMBOL_GPL(devm_create_dax_dev); EXPORT_SYMBOL_GPL(devm_create_dax_dev);
......
...@@ -13,12 +13,13 @@ ...@@ -13,12 +13,13 @@
#ifndef __DAX_H__ #ifndef __DAX_H__
#define __DAX_H__ #define __DAX_H__
struct device; struct device;
struct dax_dev;
struct resource; struct resource;
struct dax_region; struct dax_region;
void dax_region_put(struct dax_region *dax_region); void dax_region_put(struct dax_region *dax_region);
struct dax_region *alloc_dax_region(struct device *parent, struct dax_region *alloc_dax_region(struct device *parent,
int region_id, struct resource *res, unsigned int align, int region_id, struct resource *res, unsigned int align,
void *addr, unsigned long flags); void *addr, unsigned long flags);
int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region,
int count); struct resource *res, int count);
#endif /* __DAX_H__ */ #endif /* __DAX_H__ */
...@@ -61,6 +61,7 @@ static int dax_pmem_probe(struct device *dev) ...@@ -61,6 +61,7 @@ static int dax_pmem_probe(struct device *dev)
int rc; int rc;
void *addr; void *addr;
struct resource res; struct resource res;
struct dax_dev *dax_dev;
struct nd_pfn_sb *pfn_sb; struct nd_pfn_sb *pfn_sb;
struct dax_pmem *dax_pmem; struct dax_pmem *dax_pmem;
struct nd_region *nd_region; struct nd_region *nd_region;
...@@ -123,12 +124,12 @@ static int dax_pmem_probe(struct device *dev) ...@@ -123,12 +124,12 @@ static int dax_pmem_probe(struct device *dev)
return -ENOMEM; return -ENOMEM;
/* TODO: support for subdividing a dax region... */ /* TODO: support for subdividing a dax region... */
rc = devm_create_dax_dev(dax_region, &res, 1); dax_dev = devm_create_dax_dev(dax_region, &res, 1);
/* child dax_dev instances now own the lifetime of the dax_region */ /* child dax_dev instances now own the lifetime of the dax_region */
dax_region_put(dax_region); dax_region_put(dax_region);
return rc; return PTR_ERR_OR_ZERO(dax_dev);
} }
static struct nd_device_driver dax_pmem_driver = { static struct nd_device_driver dax_pmem_driver = {
......
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