public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvdimm: check for null return of devm_kmalloc in nd_pfn_probe
@ 2023-02-26  5:56 Kang Chen
  2023-02-26 20:46 ` Alison Schofield
  0 siblings, 1 reply; 2+ messages in thread
From: Kang Chen @ 2023-02-26  5:56 UTC (permalink / raw)
  To: dan.j.williams
  Cc: vishal.l.verma, dave.jiang, ira.weiny, nvdimm, linux-kernel,
	Kang Chen

devm_kmalloc may fails, pfn_sb might be null and will cause
null pointer dereference later.

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/nvdimm/pfn_devs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index af7d93015..d24fad175 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -640,6 +640,8 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns)
 	if (!pfn_dev)
 		return -ENOMEM;
 	pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
+	if (!pfn_sb)
+		return -ENOMEM;
 	nd_pfn = to_nd_pfn(pfn_dev);
 	nd_pfn->pfn_sb = pfn_sb;
 	rc = nd_pfn_validate(nd_pfn, PFN_SIG);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-26 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-26  5:56 [PATCH] nvdimm: check for null return of devm_kmalloc in nd_pfn_probe Kang Chen
2023-02-26 20:46 ` Alison Schofield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox