Skip to contentSkip to conversation

libnvdimm, dax: Fix a missing check in nd_dax_probe()

PATCH New [email protected] 1 participant 1 message Mar 17, 2021 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvdimm, dax: Fix a missing check in nd_dax_probe()

From: Yingjie Wang <[email protected]>

In nd_dax_probe(), 'nd_dax' is allocated by nd_dax_alloc(). nd_dax_alloc() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference
a bit later in the code.

Fixes c5ed9268643c ("libnvdimm, dax: autodetect support")
---
 drivers/nvdimm/dax_devs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvdimm/dax_devs.c +2 -0
index 99965077bac4..b1426ac03f01 100644
@@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
 
 	nvdimm_bus_lock(&ndns->dev);
 	nd_dax = nd_dax_alloc(nd_region);
+	if (!nd_dax)
+		return -ENOMEM;
 	nd_pfn = &nd_dax->nd_pfn;
 	dax_dev = nd_pfn_devinit(nd_pfn, ndns);
 	nvdimm_bus_unlock(&ndns->dev);
Signature · 4 lines
2.7.4
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]