Skip to content

Commit 486fa92

Browse files
Aditya Pakkidjbw
authored andcommitted
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: Aditya Pakki <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 55c1fc0 commit 486fa92

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/nvdimm/btt_devs.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
198198
return NULL;
199199

200200
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
201-
if (nd_btt->id < 0) {
202-
kfree(nd_btt);
203-
return NULL;
204-
}
201+
if (nd_btt->id < 0)
202+
goto out_nd_btt;
205203

206204
nd_btt->lbasize = lbasize;
207-
if (uuid)
205+
if (uuid) {
208206
uuid = kmemdup(uuid, 16, GFP_KERNEL);
207+
if (!uuid)
208+
goto out_put_id;
209+
}
209210
nd_btt->uuid = uuid;
210211
dev = &nd_btt->dev;
211212
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,
220221
return NULL;
221222
}
222223
return dev;
224+
225+
out_put_id:
226+
ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
227+
228+
out_nd_btt:
229+
kfree(nd_btt);
230+
return NULL;
223231
}
224232

225233
struct device *nd_btt_create(struct nd_region *nd_region)

0 commit comments

Comments
 (0)