Skip to content

Commit bbb3be1

Browse files
committed
device-dax: fix sysfs duplicate warnings
Fix warnings of the form... WARNING: CPU: 10 PID: 4983 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x62/0x80 sysfs: cannot create duplicate filename '/class/dax/dax12.0' Call Trace: dump_stack+0x63/0x86 __warn+0xcb/0xf0 warn_slowpath_fmt+0x5a/0x80 ? kernfs_path_from_node+0x4f/0x60 sysfs_warn_dup+0x62/0x80 sysfs_do_create_link_sd.isra.2+0x97/0xb0 sysfs_create_link+0x25/0x40 device_add+0x266/0x630 devm_create_dax_dev+0x2cf/0x340 [dax] dax_pmem_probe+0x1f5/0x26e [dax_pmem] nvdimm_bus_probe+0x71/0x120 ...by reusing the namespace id for the device-dax instance name. Now that we have decided that there will never by more than one device-dax instance per libnvdimm-namespace parent device [1], we can directly reuse the namepace ids. There are some possible follow-on cleanups, but those are saved for a later patch to simplify the -stable backport. [1]: https://lists.01.org/pipermail/linux-nvdimm/2016-December/008266.html Fixes: 98a29c3 ("libnvdimm, namespace: allow creation of multiple pmem...") Cc: Jeff Moyer <[email protected]> Cc: <[email protected]> Reported-by: Dariusz Dokupil <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 23b9bab commit bbb3be1

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

drivers/dax/device-dax.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ struct dax_region *alloc_dax_region(struct device *parent,
2121
int region_id, struct resource *res, unsigned int align,
2222
void *addr, unsigned long flags);
2323
struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
24-
struct resource *res, int count);
24+
int id, struct resource *res, int count);
2525
#endif /* __DEVICE_DAX_H__ */

drivers/dax/device.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ static void dev_dax_release(struct device *dev)
529529
struct dax_region *dax_region = dev_dax->region;
530530
struct dax_device *dax_dev = dev_dax->dax_dev;
531531

532-
ida_simple_remove(&dax_region->ida, dev_dax->id);
532+
if (dev_dax->id >= 0)
533+
ida_simple_remove(&dax_region->ida, dev_dax->id);
533534
dax_region_put(dax_region);
534535
put_dax(dax_dev);
535536
kfree(dev_dax);
@@ -559,7 +560,7 @@ static void unregister_dev_dax(void *dev)
559560
}
560561

561562
struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
562-
struct resource *res, int count)
563+
int id, struct resource *res, int count)
563564
{
564565
struct device *parent = dax_region->dev;
565566
struct dax_device *dax_dev;
@@ -590,10 +591,16 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
590591
if (i < count)
591592
goto err_id;
592593

593-
dev_dax->id = ida_simple_get(&dax_region->ida, 0, 0, GFP_KERNEL);
594-
if (dev_dax->id < 0) {
595-
rc = dev_dax->id;
596-
goto err_id;
594+
if (id < 0) {
595+
id = ida_simple_get(&dax_region->ida, 0, 0, GFP_KERNEL);
596+
dev_dax->id = id;
597+
if (id < 0) {
598+
rc = id;
599+
goto err_id;
600+
}
601+
} else {
602+
/* region provider owns @id lifetime */
603+
dev_dax->id = -1;
597604
}
598605

599606
/*
@@ -625,7 +632,7 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
625632
dev->parent = parent;
626633
dev->groups = dax_attribute_groups;
627634
dev->release = dev_dax_release;
628-
dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id);
635+
dev_set_name(dev, "dax%d.%d", dax_region->id, id);
629636

630637
rc = cdev_device_add(cdev, dev);
631638
if (rc) {
@@ -641,7 +648,8 @@ struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
641648
return dev_dax;
642649

643650
err_dax:
644-
ida_simple_remove(&dax_region->ida, dev_dax->id);
651+
if (dev_dax->id >= 0)
652+
ida_simple_remove(&dax_region->ida, dev_dax->id);
645653
err_id:
646654
kfree(dev_dax);
647655

drivers/dax/pmem.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ static void dax_pmem_percpu_kill(void *data)
5858

5959
static int dax_pmem_probe(struct device *dev)
6060
{
61-
int rc;
6261
void *addr;
6362
struct resource res;
63+
int rc, id, region_id;
6464
struct nd_pfn_sb *pfn_sb;
6565
struct dev_dax *dev_dax;
6666
struct dax_pmem *dax_pmem;
67-
struct nd_region *nd_region;
6867
struct nd_namespace_io *nsio;
6968
struct dax_region *dax_region;
7069
struct nd_namespace_common *ndns;
@@ -123,14 +122,17 @@ static int dax_pmem_probe(struct device *dev)
123122
/* adjust the dax_region resource to the start of data */
124123
res.start += le64_to_cpu(pfn_sb->dataoff);
125124

126-
nd_region = to_nd_region(dev->parent);
127-
dax_region = alloc_dax_region(dev, nd_region->id, &res,
125+
rc = sscanf(dev_name(&ndns->dev), "namespace%d.%d", &region_id, &id);
126+
if (rc != 2)
127+
return -EINVAL;
128+
129+
dax_region = alloc_dax_region(dev, region_id, &res,
128130
le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP);
129131
if (!dax_region)
130132
return -ENOMEM;
131133

132134
/* TODO: support for subdividing a dax region... */
133-
dev_dax = devm_create_dev_dax(dax_region, &res, 1);
135+
dev_dax = devm_create_dev_dax(dax_region, id, &res, 1);
134136

135137
/* child dev_dax instances now own the lifetime of the dax_region */
136138
dax_region_put(dax_region);

0 commit comments

Comments
 (0)