Commit 486fa92d authored by Aditya Pakki's avatar Aditya Pakki Committed by Dan Williams

libnvdimm/btt: Fix a kmemdup failure check

In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.
Signed-off-by: default avatarAditya Pakki <pakki001@umn.edu>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 55c1fc0a
...@@ -198,14 +198,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region, ...@@ -198,14 +198,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL; return NULL;
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL); nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
if (nd_btt->id < 0) { if (nd_btt->id < 0)
kfree(nd_btt); goto out_nd_btt;
return NULL;
}
nd_btt->lbasize = lbasize; nd_btt->lbasize = lbasize;
if (uuid) if (uuid) {
uuid = kmemdup(uuid, 16, GFP_KERNEL); uuid = kmemdup(uuid, 16, GFP_KERNEL);
if (!uuid)
goto out_put_id;
}
nd_btt->uuid = uuid; nd_btt->uuid = uuid;
dev = &nd_btt->dev; dev = &nd_btt->dev;
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id); dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
...@@ -220,6 +221,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region, ...@@ -220,6 +221,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL; return NULL;
} }
return dev; return dev;
out_put_id:
ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
out_nd_btt:
kfree(nd_btt);
return NULL;
} }
struct device *nd_btt_create(struct nd_region *nd_region) struct device *nd_btt_create(struct nd_region *nd_region)
......
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