diff mbox series

nvdimm/test: Fix corruption due to memory overflow

Message ID 20210604070828.2747433-1-santosh@fossix.org (mailing list archive)
State New
Headers show
Series nvdimm/test: Fix corruption due to memory overflow | expand

Commit Message

Santosh Sivaraj June 4, 2021, 7:08 a.m. UTC
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.

Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
 tools/testing/nvdimm/test/ndtest.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 09d98317bf4e..960a37aa3f07 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -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);