Skip to content

Commit d9cee9f

Browse files
committed
libnvdimm/region: Fix label activation vs errors
There are a few scenarios where init_active_labels() can return without registering deactivate_labels() to run when the region is disabled. In particular label error injection creates scenarios where a DIMM is disabled, but labels on other DIMMs in the region become activated. Arrange for init_active_labels() to always register deactivate_labels(). Reported-by: Krzysztof Kensicki <[email protected]> Cc: <[email protected]> Fixes: bf9bccc ("libnvdimm: pmem label sets and namespace instantiation.") Reviewed-by: Jeff Moyer <[email protected]> Link: https://lore.kernel.org/r/162766356450.3223041.1183118139023841447.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent b93dfa6 commit d9cee9f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/nvdimm/namespace_devs.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ static void deactivate_labels(void *region)
25272527

25282528
static int init_active_labels(struct nd_region *nd_region)
25292529
{
2530-
int i;
2530+
int i, rc = 0;
25312531

25322532
for (i = 0; i < nd_region->ndr_mappings; i++) {
25332533
struct nd_mapping *nd_mapping = &nd_region->mapping[i];
@@ -2546,13 +2546,14 @@ static int init_active_labels(struct nd_region *nd_region)
25462546
else if (test_bit(NDD_LABELING, &nvdimm->flags))
25472547
/* fail, labels needed to disambiguate dpa */;
25482548
else
2549-
return 0;
2549+
continue;
25502550

25512551
dev_err(&nd_region->dev, "%s: is %s, failing probe\n",
25522552
dev_name(&nd_mapping->nvdimm->dev),
25532553
test_bit(NDD_LOCKED, &nvdimm->flags)
25542554
? "locked" : "disabled");
2555-
return -ENXIO;
2555+
rc = -ENXIO;
2556+
goto out;
25562557
}
25572558
nd_mapping->ndd = ndd;
25582559
atomic_inc(&nvdimm->busy);
@@ -2586,13 +2587,17 @@ static int init_active_labels(struct nd_region *nd_region)
25862587
break;
25872588
}
25882589

2589-
if (i < nd_region->ndr_mappings) {
2590+
if (i < nd_region->ndr_mappings)
2591+
rc = -ENOMEM;
2592+
2593+
out:
2594+
if (rc) {
25902595
deactivate_labels(nd_region);
2591-
return -ENOMEM;
2596+
return rc;
25922597
}
25932598

25942599
return devm_add_action_or_reset(&nd_region->dev, deactivate_labels,
2595-
nd_region);
2600+
nd_region);
25962601
}
25972602

25982603
int nd_region_register_namespaces(struct nd_region *nd_region, int *err)

0 commit comments

Comments
 (0)