[PATCH] libnvdimm/of_pmem: check the return value of kstrdup()

From: Xiaoke Wang
Date: Sun Dec 12 2021 - 22:15:33 EST


kstrdup() returns NULL when some internal memory erros happen, it is
better to check the return value of it so to catch the memory error in
time.

Signed-off-by: Xiaoke Wang <xkernel.wang@xxxxxxxxxxx>
---
drivers/nvdimm/of_pmem.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 10dbdcd..33978d2 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -31,6 +31,10 @@ static int of_pmem_region_probe(struct platform_device *pdev)
return -ENOMEM;

priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL);
+ if (!priv->bus_desc.provider_name) {
+ kfree(priv);
+ return -ENOMEM;
+ }
priv->bus_desc.module = THIS_MODULE;
priv->bus_desc.of_node = np;

--