Message ID | 20221125020825.37125-1-yuancan@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | ndtest: Add checks for devm_kcalloc | expand |
On 11/25/22 07:38, Yuan Can wrote: > 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. > Fixes: 9399ab61ad82 ("ndtest: Add dimms to the two buses") > Signed-off-by: Yuan Can <yuancan@huawei.com> > --- > 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)
在 2022/12/2 19:29, Shivaprasad G Bhat 写道: > On 11/25/22 07:38, Yuan Can wrote: >> 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!
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)
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") Signed-off-by: Yuan Can <yuancan@huawei.com> --- tools/testing/nvdimm/test/ndtest.c | 2 ++ 1 file changed, 2 insertions(+)