libnvdimm, namespace: potential NULL deref on allocation error
Subsystems (2)
PATCH 1/1 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 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')
Signed-off-by Dan Carpenter <[email protected]>
drivers/nvdimm/namespace_devs.c +8 -6
@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region)return devs; err: -for (i =0 ; devs[i]; i++) -if (is_nd_blk (&nd_region->dev)) -namespace_blk_release (devs[i]); -else -namespace_pmem_release (devs[i]); -kfree (devs); +if (devs) { +for (i =0 ; devs[i]; i++) +if (is_nd_blk (&nd_region->dev)) +namespace_blk_release (devs[i]); +else +namespace_pmem_release (devs[i]); +kfree (devs); + }return NULL ; }
Dan Williams
AppliedQuoted 5 lines · Dan Carpenter
If the
kcalloc()fails then "devs" can be NULL and we dereference it checking "devs[i]".Fixes 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')Signed-off-by Dan Carpenter <[email protected]>
Thanks, applied.