Skip to contentSkip to conversation

libnvdimm: fix dereference on null devs on error exit path

PATCH In review Colin King 2 participants 2 messages Oct 15, 2016 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 libnvdimm: fix dereference on null devs on error exit path

From: Colin Ian King <[email protected]>

If devs cannot be allocated then the error exit path jumps to a cleanup loop that iterates over a null array of devs which is incorrect. Fix this by jumping instead to the end of the function where NULL is returned.

---
 drivers/nvdimm/namespace_devs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvdimm/namespace_devs.c +2 -1
index 3509cff..5d2755a 100644
@@ -2125,7 +2125,7 @@ static struct device **scan_labels(struct nd_region *nd_region)
 
 		devs = kcalloc(2, sizeof(dev), GFP_KERNEL);
 		if (!devs)
-			goto err;
+			goto err_ret;
 		if (is_nd_blk(&nd_region->dev)) {
 			struct nd_namespace_blk *nsblk;
 
@@ -2182,6 +2182,7 @@ static struct device **scan_labels(struct nd_region *nd_region)
 		else
 			namespace_pmem_release(devs[i]);
 	kfree(devs);
+ err_ret:
 	return NULL;
 }
 
Signature · 6 lines
2.9.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 8 lines · Colin King

From: Colin Ian King <[email protected]>

If devs cannot be allocated then the error exit path jumps to a cleanup loop that iterates over a null array of devs which is incorrect. Fix this by jumping instead to the end of the function where NULL is returned.

Thanks, I've already applied a similar fix from Dan Carpenter.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm