All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuan Can <yuancan@huawei.com>
To: <dan.j.williams@intel.com>, <vishal.l.verma@intel.com>,
	<dave.jiang@intel.com>, <ira.weiny@intel.com>,
	<sbhat@linux.ibm.com>, <santosh@fossix.org>,
	<nvdimm@lists.linux.dev>
Cc: <yuancan@huawei.com>
Subject: [PATCH v2] ndtest: Add checks for devm_kcalloc
Date: Sat, 3 Dec 2022 06:18:48 +0000	[thread overview]
Message-ID: <20221203061848.113561-1-yuancan@huawei.com> (raw)

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


                 reply	other threads:[~2022-12-03  6:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221203061848.113561-1-yuancan@huawei.com \
    --to=yuancan@huawei.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=santosh@fossix.org \
    --cc=sbhat@linux.ibm.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.