From: Alison Schofield <alison.schofield@intel.com>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Santosh Sivaraj <santosh@fossix.org>, <nvdimm@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH] nvdimm: ndtest: Add check for devm_kcalloc() allocations in ndtest_probe()
Date: Thu, 18 Sep 2025 10:18:23 -0700 [thread overview]
Message-ID: <aMw-320nl1PJBlCm@aschofie-mobl2.lan> (raw)
In-Reply-To: <20250918141606.3589435-1-lgs201920130244@gmail.com>
On Thu, Sep 18, 2025 at 10:16:06PM +0800, Guangshuo Li wrote:
> devm_kcalloc() may fail. ndtest_probe() allocates three DMA address
> arrays (dcr_dma, label_dma, dimm_dma) and later unconditionally uses
> them in ndtest_nvdimm_init(), which can lead to a NULL pointer
> dereference on allocation failure.
>
> Add NULL checks for all three allocations and return -ENOMEM if any
> allocation fails.
>
> Fixes: 9399ab61ad82 ("ndtest: Add dimms to the two buses")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> tools/testing/nvdimm/test/ndtest.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
> index 68a064ce598c..516f304bb0b9 100644
> --- a/tools/testing/nvdimm/test/ndtest.c
> +++ b/tools/testing/nvdimm/test/ndtest.c
> @@ -855,6 +855,11 @@ static int ndtest_probe(struct platform_device *pdev)
> 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) {
> + pr_err("%s: failed to allocate DMA address arrays\n", __func__);
> + return -ENOMEM;
> + }
> +
Hi Guangshuo Li,
Can you check on correctness of inserting that pr_err()?
ie. does it fall into the category of excessive OOM messaging?
> rc = ndtest_nvdimm_init(p);
> if (rc)
> goto err;
> --
> 2.43.0
>
>
prev parent reply other threads:[~2025-09-18 17:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 14:16 Guangshuo Li
2025-09-18 17:18 ` Alison Schofield [this message]
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=aMw-320nl1PJBlCm@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=ira.weiny@intel.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=santosh@fossix.org \
--cc=stable@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®