1 From 7a47db31380b65bcc2aedffb39509f8ca936d8f6 Mon Sep 17 00:00:00 2001
2 From: Kangjie Lu <kjlu@umn.edu>
3 Date: Tue, 12 Mar 2019 03:20:34 -0500
4 Subject: libnvdimm/namespace: Fix a potential NULL pointer dereference
6 [ Upstream commit 55c1fc0af29a6c1b92f217b7eb7581a882e0c07c ]
8 In case kmemdup fails, the fix goes to blk_err to avoid NULL
11 Signed-off-by: Kangjie Lu <kjlu@umn.edu>
12 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
13 Signed-off-by: Sasha Levin <sashal@kernel.org>
15 drivers/nvdimm/namespace_devs.c | 5 ++++-
16 1 file changed, 4 insertions(+), 1 deletion(-)
18 diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
19 index 9bc5f555ee686..cf4a90b50f8b8 100644
20 --- a/drivers/nvdimm/namespace_devs.c
21 +++ b/drivers/nvdimm/namespace_devs.c
22 @@ -2028,9 +2028,12 @@ struct device *create_namespace_blk(struct nd_region *nd_region,
25 memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
28 nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
30 + if (!nsblk->alt_name)
33 res = nsblk_add_resource(nd_region, ndd, nsblk,
34 __le64_to_cpu(nd_label->dpa));