mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] libnvdimm/of_pmem: check the return value of kstrdup()
@ 2021-12-13  3:13 Xiaoke Wang
  0 siblings, 0 replies; only message in thread
From: Xiaoke Wang @ 2021-12-13  3:13 UTC (permalink / raw)
  To: oohall; +Cc: nvdimm, linux-kernel, Xiaoke Wang

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@foxmail.com>
---
 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;
 
-- 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-13  3:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  3:13 [PATCH] libnvdimm/of_pmem: check the return value of kstrdup() Xiaoke Wang

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®