@@ -583,7 +583,11 @@ static void dax_region_unregister(void *region)
dax_region_put(dax_region);
}
-/* The dax_region reference returned should be dropped with dax_region_put() */
+/*
+ * Caller is responsible to ensure the parent device stays live while the
+ * returned dax_region is in use. Or as is typically the case, a separate
+ * reference should be taken.
+ */
struct dax_region *alloc_dax_region(struct device *parent, int region_id,
struct range *range, int target_node, unsigned int align,
unsigned long flags)
@@ -626,13 +630,8 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id,
return NULL;
}
- /* Hold a reference to return to the caller */
- kref_get(&dax_region->kref);
- if (devm_add_action_or_reset(parent, dax_region_unregister,
- dax_region)) {
- kref_put(&dax_region->kref, dax_region_free);
+ if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region))
return NULL;
- }
return dax_region;
}
EXPORT_SYMBOL_GPL(alloc_dax_region);
@@ -29,10 +29,6 @@ static int cxl_dax_region_probe(struct device *dev)
.size = range_len(&cxlr_dax->hpa_range),
};
dev_dax = devm_create_dev_dax(&data);
-
- /* child dev_dax instances now own the lifetime of the dax_region */
- dax_region_put(dax_region);
-
return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0;
}
@@ -39,9 +39,6 @@ static int dax_hmem_probe(struct platform_device *pdev)
.size = region_idle ? 0 : range_len(&mri->range),
};
dev_dax = devm_create_dev_dax(&data);
-
- /* child dev_dax instances now own the lifetime of the dax_region */
- dax_region_put(dax_region);
return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0;
}
@@ -13,7 +13,6 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
int rc, id, region_id;
resource_size_t offset;
struct nd_pfn_sb *pfn_sb;
- struct dev_dax *dev_dax;
struct dev_dax_data data;
struct nd_namespace_io *nsio;
struct dax_region *dax_region;
@@ -65,12 +64,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
.pgmap = &pgmap,
.size = range_len(&range),
};
- dev_dax = devm_create_dev_dax(&data);
-
- /* child dev_dax instances now own the lifetime of the dax_region */
- dax_region_put(dax_region);
-
- return dev_dax;
+ return devm_create_dev_dax(&data);
}
static int dax_pmem_probe(struct device *dev)
All the callers to alloc_dax_region() maintain the device associated with the dax_region until the dax_region is referenced by the dax_dev they are creating. Remove the extra kref that alloc_dax_region() takes. Add a comment to clarify the reference counting should additional callers be grown later. Cc: Yongqiang Liu <liuyongqiang13@huawei.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Paul Cassella <cassella@hpe.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com> --- drivers/dax/bus.c | 13 ++++++------- drivers/dax/cxl.c | 4 ---- drivers/dax/hmem/hmem.c | 3 --- drivers/dax/pmem.c | 8 +------- 4 files changed, 7 insertions(+), 21 deletions(-)