Skip to contentSkip to conversation

nvdimm/test: Fix corruption due to memory overflow

PATCH New Santosh Sivaraj 1 participant 1 message Jun 4, 2021 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvdimm/test: Fix corruption due to memory overflow

The test allocates memory only for 4 DIMMS but more dimms are configured, due to which the module crashes on exit, strangely this was not observed on x86 so far, but very easily reproduced on PowerPC.

---
 tools/testing/nvdimm/test/ndtest.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
tools/testing/nvdimm/test/ndtest.c +5 -6
index 09d98317bf4e..960a37aa3f07 100644
@@ -22,7 +22,6 @@ enum {
 	DIMM_SIZE = SZ_32M,
 	LABEL_SIZE = SZ_128K,
 	NUM_INSTANCES = 2,
-	NUM_DCR = 4,
 	NDTEST_MAX_MAPPING = 6,
 };
 
@@ -1606,8 +1605,6 @@ static const struct attribute_group *ndtest_attribute_groups[] = {
 
 static int ndtest_bus_register(struct ndtest_priv *p)
 {
-	p->config = &bus_configs[p->pdev.id];
-
 	p->bus_desc.ndctl = ndtest_ctl;
 	p->bus_desc.module = THIS_MODULE;
 	p->bus_desc.provider_name = NULL;
@@ -1667,14 +1664,16 @@ static int ndtest_probe(struct platform_device *pdev)
 	int rc;
 
 	p = to_ndtest_priv(&pdev->dev);
+	p->config = &bus_configs[pdev->id];
+
 	if (ndtest_bus_register(p))
 		return -ENOMEM;
 
-	p->dcr_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
+	p->dcr_dma = devm_kcalloc(&p->pdev.dev, p->config->dimm_count,
 				 sizeof(dma_addr_t), GFP_KERNEL);
-	p->label_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
+	p->label_dma = devm_kcalloc(&p->pdev.dev, p->config->dimm_count,
 				   sizeof(dma_addr_t), GFP_KERNEL);
-	p->dimm_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
+	p->dimm_dma = devm_kcalloc(&p->pdev.dev, p->config->dimm_count,
 				  sizeof(dma_addr_t), GFP_KERNEL);
 
 	rc = ndtest_nvdimm_init(p);
Signature · 1 line
2.31.1