Commit 75d29713 authored by Dan Carpenter's avatar Dan Carpenter Committed by Dan Williams

libnvdimm, namespace: potential NULL deref on allocation error

If the kcalloc() fails then "devs" can be NULL and we dereference it
checking "devs[i]".

Fixes: 1b40e09a ('libnvdimm: blk labels and namespace instantiation')
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 1001354c
...@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region) ...@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region)
return devs; return devs;
err: err:
for (i = 0; devs[i]; i++) if (devs) {
if (is_nd_blk(&nd_region->dev)) for (i = 0; devs[i]; i++)
namespace_blk_release(devs[i]); if (is_nd_blk(&nd_region->dev))
else namespace_blk_release(devs[i]);
namespace_pmem_release(devs[i]); else
kfree(devs); namespace_pmem_release(devs[i]);
kfree(devs);
}
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment