Skip to contentSkip to conversation

nvdimm: namespace_devs: fix a potential NULL pointer dereference

PATCH New Kangjie Lu 1 participant 1 message Mar 12, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 nvdimm: namespace_devs: fix a potential NULL pointer dereference

In case kmemdup fails, the fix goes to blk_err to avoid NULL pointer dereference

---
 drivers/nvdimm/namespace_devs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvdimm/namespace_devs.c +4 -1
index 4b077555ac70..6f65261e151f 100644
@@ -2245,9 +2245,12 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
 	if (!nsblk->uuid)
 		goto blk_err;
 	memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
-	if (name[0])
+	if (name[0]) {
 		nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
 				GFP_KERNEL);
+		if (!nsblk->alt_name)
+			goto blk_err;
+	}
 	res = nsblk_add_resource(nd_region, ndd, nsblk,
 			__le64_to_cpu(nd_label->dpa));
 	if (!res)
Signature · 1 line
2.17.1