NVDIMM Device and Persistent Memory development
 help / color / mirror / Atom feed
* [PATCH v2] ndtest: Add checks for devm_kcalloc
@ 2022-12-03  6:18 Yuan Can
  0 siblings, 0 replies; only message in thread
From: Yuan Can @ 2022-12-03  6:18 UTC (permalink / raw
  To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, sbhat,
	santosh, nvdimm
  Cc: yuancan

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

Fixes: 9399ab61ad82 ("ndtest: Add dimms to the two buses")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
Changes in v2:
- Fix typo in commit message

 tools/testing/nvdimm/test/ndtest.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 01ceb98c15a0..94fbb9d0fb6a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -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)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-03  6:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-03  6:18 [PATCH v2] ndtest: Add checks for devm_kcalloc Yuan Can

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).