Skip to contentSkip to conversation

ndtest: Add checks for devm_kcalloc

PATCH Superseded Yuan Can 2 participants 3 messages Nov 25, 2022 – Dec 3, 2022 libnvdimm: non-volatile memory device

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 ndtest: Add checks for devm_kcalloc

As the devm_kcalloc may return NULL, the return value needs to be checked to avoid NULL poineter dereference.

Fixes 9399ab61ad82 ("ndtest: Add dimms to the two buses")
---
 tools/testing/nvdimm/test/ndtest.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/nvdimm/test/ndtest.c +2 -0
index 01ceb98c15a0..94fbb9d0fb6a 100644
@@ -849,6 +849,8 @@ static int ndtest_probe(struct platform_device *pdev)
 				   sizeof(dma_addr_t), GFP_KERNEL);
 	p->dimm_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
 				  sizeof(dma_addr_t), GFP_KERNEL);
+	if (!p->dcr_dma || !p->label_dma || !p->dimm_dma)
+		return -ENOMEM;
 
 	rc = ndtest_nvdimm_init(p);
 	if (rc)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Yuan Can

As the devm_kcalloc may return NULL, the return value needs to be checked to avoid NULL poineter dereference.

s/poineter/pointer

Patch looks good to me otherwise.

Quoted 19 lines
Fixes 9399ab61ad82 ("ndtest: Add dimms to the two buses")
---
  tools/testing/nvdimm/test/ndtest.c | 2 ++
  1 file changed, 2 insertions(+)
tools/testing/nvdimm/test/ndtest.c +2 -0
index 01ceb98c15a0..94fbb9d0fb6a 100644
@@ -849,6 +849,8 @@ static int ndtest_probe(struct platform_device *pdev)
  				   sizeof(dma_addr_t), GFP_KERNEL);
  	p->dimm_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
  				  sizeof(dma_addr_t), GFP_KERNEL);
+	if (!p->dcr_dma || !p->label_dma || !p->dimm_dma)
+		return -ENOMEM;
 
  	rc = ndtest_nvdimm_init(p);
  	if (rc)
author
#2 lore raw
Quoted 7 lines · Shivaprasad G Bhat
Quoted 2 lines · Yuan Can

As the devm_kcalloc may return NULL, the return value needs to be checked to avoid NULL poineter dereference.

s/poineter/pointer

Patch looks good to me otherwise.

Thanks for the review!

Signature · 2 lines
Best regards,
Yuan Can