Skip to content

Commit a9e6aa9

Browse files
lgs2513weiny2
authored andcommitted
nvdimm: ndtest: Return -ENOMEM if devm_kcalloc() fails in ndtest_probe()
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 under low-memory conditions. Check all three allocations and return -ENOMEM if any allocation fails, jumping to the common error path. Do not emit an extra error message since the allocator already warns on allocation failure. Fixes: 9399ab6 ("ndtest: Add dimms to the two buses") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
1 parent 8850643 commit a9e6aa9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/testing/nvdimm/test/ndtest.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,22 @@ static int ndtest_probe(struct platform_device *pdev)
850850

851851
p->dcr_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
852852
sizeof(dma_addr_t), GFP_KERNEL);
853+
if (!p->dcr_dma) {
854+
rc = -ENOMEM;
855+
goto err;
856+
}
853857
p->label_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
854858
sizeof(dma_addr_t), GFP_KERNEL);
859+
if (!p->label_dma) {
860+
rc = -ENOMEM;
861+
goto err;
862+
}
855863
p->dimm_dma = devm_kcalloc(&p->pdev.dev, NUM_DCR,
856864
sizeof(dma_addr_t), GFP_KERNEL);
857-
865+
if (!p->dimm_dma) {
866+
rc = -ENOMEM;
867+
goto err;
868+
}
858869
rc = ndtest_nvdimm_init(p);
859870
if (rc)
860871
goto err;

0 commit comments

Comments
 (0)