Skip to content

Commit c969e24

Browse files
committed
libnvdimm, namespace: filter out of range labels in scan_labels()
Short-circuit doomed-to-fail label validation attempts by skipping labels that are outside the given region. For example a DIMM that has multiple PMEM regions will waste time attempting to create namespaces only to find that the interleave-set-cookie does not validate, e.g.: nd_region region6: invalid cookie in label: 73e608dc-47b9-4b2a-b5c7-2d55a32e0c2 Similar to how we skip BLK labels when performing PMEM validation we can skip out-of-range labels early. Signed-off-by: Dan Williams <[email protected]>
1 parent 762d067 commit c969e24

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/nvdimm/namespace_devs.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,10 +2013,11 @@ static int cmp_dpa(const void *a, const void *b)
20132013

20142014
static struct device **scan_labels(struct nd_region *nd_region)
20152015
{
2016-
struct nd_mapping *nd_mapping = &nd_region->mapping[0];
2016+
int i, count = 0;
20172017
struct device *dev, **devs = NULL;
20182018
struct nd_label_ent *label_ent, *e;
2019-
int i, count = 0;
2019+
struct nd_mapping *nd_mapping = &nd_region->mapping[0];
2020+
resource_size_t map_end = nd_mapping->start + nd_mapping->size - 1;
20202021

20212022
/* "safe" because create_namespace_pmem() might list_move() label_ent */
20222023
list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) {
@@ -2033,6 +2034,10 @@ static struct device **scan_labels(struct nd_region *nd_region)
20332034
else
20342035
continue;
20352036

2037+
/* skip labels that describe extents outside of the region */
2038+
if (nd_label->dpa < nd_mapping->start || nd_label->dpa > map_end)
2039+
continue;
2040+
20362041
i = add_namespace_resource(nd_region, nd_label, devs, count);
20372042
if (i < 0)
20382043
goto err;

0 commit comments

Comments
 (0)