libnvdimm, region, pmem: fix 'badblocks' sysfs_get_dirent() reference lifetime

We need to hold a reference on the 'dirent' until we are sure there are
no more notifications that will be sent. As noted in the new comments we
take advantage of the fact that the references are taken and dropped
under device_lock() and that nd_device_notify() holds device_lock() over
new badblocks notifications. The notifications that happen when
badblocks are cleared only occur while the device is active.

Also take the opportunity to fix up the error messages to report the
user visible effect of a sysfs_get_dirent() failure.

Fixes: 975750a98c ("libnvdimm, pmem: Add sysfs notifications to badblocks")
Cc: Toshi Kani <toshi.kani@hpe.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
Dan Williams
2017-06-30 18:56:03 -07:00
szülő 7e5a21dfe5
commit 6aa734a2f3
2 fájl változott, egészen pontosan 21 új sor hozzáadva és 8 régi sor törölve

Fájl megtekintése

@@ -60,11 +60,9 @@ static int nd_region_probe(struct device *dev)
return -ENODEV;
nd_region->bb_state = sysfs_get_dirent(nd_region->dev.kobj.sd,
"badblocks");
if (nd_region->bb_state)
sysfs_put(nd_region->bb_state);
else
if (!nd_region->bb_state)
dev_warn(&nd_region->dev,
"sysfs_get_dirent 'badblocks' failed\n");
"'badblocks' notification disabled\n");
ndr_res.start = nd_region->ndr_start;
ndr_res.end = nd_region->ndr_start + nd_region->ndr_size - 1;
nvdimm_badblocks_populate(nd_region, &nd_region->bb, &ndr_res);
@@ -111,6 +109,13 @@ static int nd_region_remove(struct device *dev)
dev_set_drvdata(dev, NULL);
nvdimm_bus_unlock(dev);
/*
* Note, this assumes device_lock() context to not race
* nd_region_notify()
*/
sysfs_put(nd_region->bb_state);
nd_region->bb_state = NULL;
return 0;
}