[PATCH ndctl] ndctl, region: return the rc value in region_action
by Yi Zhang
if region_action failed, return the rc valude instead of 0
Signed-off-by: Yi Zhang <yi.zhang(a)redhat.com>
---
ndctl/region.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ndctl/region.c b/ndctl/region.c
index 993b3f8..7945007 100644
--- a/ndctl/region.c
+++ b/ndctl/region.c
@@ -89,7 +89,7 @@ static int region_action(struct ndctl_region *region, enum device_action mode)
break;
}
- return 0;
+ return rc;
}
static int do_xable_region(const char *region_arg, enum device_action mode,
--
2.17.2
3 years, 1 month
[ndctl PATCH] contrib: add an example qemu setup script for HMAT emulation
by Vishal Verma
Add a script to demonstrate HMAT emulation using qemu by injecting the
initramfs with a made-up ACPI HMAT table.
Cc: Dan Williams <dan.j.williams(a)intel.com>
Originally-authored-by: Keith Busch <keith.busch(a)intel.com>
[vishal: minor shellcheck fixups]
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
contrib/daxctl-qemu-hmat-setup | 211 +++++++++++++++++++++++++++++++++
1 file changed, 211 insertions(+)
create mode 100755 contrib/daxctl-qemu-hmat-setup
diff --git a/contrib/daxctl-qemu-hmat-setup b/contrib/daxctl-qemu-hmat-setup
new file mode 100755
index 0000000..0670e99
--- /dev/null
+++ b/contrib/daxctl-qemu-hmat-setup
@@ -0,0 +1,211 @@
+#!/bin/bash -e
+
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2019 Intel Corporation. All rights reserved.
+
+KERNEL=${KERNEL:-$(uname -r)}
+ROOT_IMAGE=${ROOT_IMAGE:-root.img}
+
+INITIATORS=4
+TARGETS=128
+TARGET_SIZE_MB=128
+TARGET_SIZE="$((TARGET_SIZE_MB * 1024 * 1024))"
+QEMU_MEM="$((TARGET_SIZE_MB * TARGETS))"
+
+for i in $(seq 0 $((TARGETS - 1))); do
+ qemu-img create -f raw "dimm-$i" "${TARGET_SIZE}"
+done;
+
+# Address Range Structures
+cat <<EOF > hmat.dsl
+ Signature : "HMAT" [Heterogeneous Memory Attributes Table]
+ Table Length : 00000200
+ Revision : 01
+ Checksum : F4
+ Oem ID : "BOCHS "
+ Oem Table ID : "BXPCHMAT"
+ Oem Revision : 00000001
+ Asl Compiler ID : "INTL"
+ Asl Compiler Revision : 20170929
+ Reserved : 00000000
+
+ Structure Type : 0000 [Memory Subystem Address Range]
+ Reserved : 0000
+ Length : 00000028
+ Flags (decoded below) : 0003
+Processor Proximity Domain Valid : 1
+ Memory Proximity Domain Valid : 1
+ Reservation Hint : 0
+ Reserved1 : 0000
+ Processor Proximity Domain : 00000000
+ Memory Proximity Domain : 00000000
+ Reserved2 : 00000000
+ Physical Address Range Base : 0000000000000000
+ Physical Address Range Size : 00000000000A0000
+
+ Structure Type : 0000 [Memory Subystem Address Range]
+ Reserved : 0000
+ Length : 00000028
+ Flags (decoded below) : 0003
+Processor Proximity Domain Valid : 1
+ Memory Proximity Domain Valid : 1
+ Reservation Hint : 0
+ Reserved1 : 0000
+ Processor Proximity Domain : 00000000
+ Memory Proximity Domain : 00000000
+ Reserved2 : 00000000
+ Physical Address Range Base : 0000000000100000
+ Physical Address Range Size : 0000000007F00000
+EOF
+
+for i in $(seq 1 $((TARGETS - 1))); do
+ BASE=$(printf "%016x" $((0x8000000 * i)))
+cat <<EOF >> hmat.dsl
+
+ Structure Type : 0000 [Memory Subystem Address Range]
+ Reserved : 0000
+ Length : 00000028
+ Flags (decoded below) : 0003
+Processor Proximity Domain Valid : 1
+ Memory Proximity Domain Valid : 1
+ Reservation Hint : 0
+ Reserved1 : 0000
+ Processor Proximity Domain : $(printf "%08x" $((i % INITIATORS)))
+ Memory Proximity Domain : $(printf "%08x" "${i}")
+ Reserved2 : 00000000
+ Physical Address Range Base : ${BASE}
+ Physical Address Range Size : 0000000008000000
+EOF
+done
+
+# System Locality Latency
+TABLE_SIZE="$(printf "%08x" $((40 + 4 * INITIATORS + 4 * TARGETS + 2 * INITIATORS * TARGETS)))"
+cat <<EOF >> hmat.dsl
+
+ Structure Type : 0001 [System Locality Latency and Bandwidth Information]
+ Reserved : 0000
+ Length : ${TABLE_SIZE}
+ Flags (decoded below) : 00
+ Memory Hierarchy : 0
+ Data Type : 00
+ Reserved1 : 0000
+ Initiator Proximity Domains # : $(printf "%08x" ${INITIATORS})
+ Target Proximity Domains # : $(printf "%08x" ${TARGETS})
+ Reserved2 : 00000000
+ Entry Base Unit : 0000000000000001
+EOF
+
+for i in $(seq 0 $((INITIATORS - 1))); do
+cat <<EOF >> hmat.dsl
+ Initiator Proximity Domain List : $(printf "%08x" "${i}")
+EOF
+done
+
+for i in $(seq 0 $((TARGETS - 1))); do
+cat <<EOF >> hmat.dsl
+ Target Proximity Domain List : $(printf "%08x" "${i}")
+EOF
+done
+
+LOCAL_START=0x10
+REMOTE_START=0x20
+for i in $(seq 0 $((INITIATORS - 1))); do
+ for j in $(seq 0 $((TARGETS - 1))); do
+ if [ "$((j % INITIATORS))" -eq "${i}" ]; then
+ cat <<EOF >> hmat.dsl
+ Entry : $(printf "%04x" $((LOCAL_START + j * 10)))
+EOF
+ else
+ cat <<EOF >> hmat.dsl
+ Entry : $(printf "%04x" $((REMOTE_START + j * 10)))
+EOF
+ fi
+ done
+done
+
+# System Locality Bandwidth
+TABLE_SIZE=$(printf "%08x" $((40 + 4 * INITIATORS + 4 * TARGETS + 2 * INITIATORS * TARGETS)))
+cat <<EOF >> hmat.dsl
+
+ Structure Type : 0001 [System Locality Latency and Bandwidth Information]
+ Reserved : 0000
+ Length : ${TABLE_SIZE}
+ Flags (decoded below) : 00
+ Memory Hierarchy : 0
+ Data Type : 03
+ Reserved1 : 0000
+ Initiator Proximity Domains # : $(printf "%08x" ${INITIATORS})
+ Target Proximity Domains # : $(printf "%08x" ${TARGETS})
+ Reserved2 : 00000000
+ Entry Base Unit : 0000000000000400
+EOF
+
+for i in $(seq 0 $((INITIATORS - 1))); do
+cat <<EOF >> hmat.dsl
+ Initiator Proximity Domain List : $(printf "%08x" "${i}")
+EOF
+done
+
+for i in $(seq 0 $((TARGETS - 1))); do
+cat <<EOF >> hmat.dsl
+ Target Proximity Domain List : $(printf "%08x" "${i}")
+EOF
+done
+
+LOCAL_START=0x2000
+REMOTE_START=0x1000
+for i in $(seq 0 $((INITIATORS - 1))); do
+ for j in $(seq 0 $((TARGETS - 1))); do
+ if [ "$((j % INITIATORS))" -eq "${i}" ]; then
+ cat <<EOF >> hmat.dsl
+ Entry : $(printf "%04x" $((LOCAL_START - j * 32)))
+EOF
+ else
+ cat <<EOF >> hmat.dsl
+ Entry : $(printf "%04x" $((REMOTE_START - j * 32)))
+EOF
+ fi
+ done
+done
+
+# Side Caches
+for i in $(seq 0 ${TARGETS}); do
+cat <<EOF >> hmat.dsl
+
+ Structure Type : 0002 [Memory Side Cache Information Structure]
+ Reserved : 0000
+ Length : 00000020
+ Memory Proximity Domain : $(printf "%08x" "${i}")
+ Reserved1 : 00000000
+ Memory Side Cache Size : 0000000000100000
+Cache Attributes (decoded below) : 01001113
+ Total Cache Levels : 1
+ Cache Level : 1
+ Cache Associativity : 1
+ Write Policy : 1
+ Cache Line Size : 0100
+ Reserved2 : 0000
+ SMBIOS Handle # : 0000
+EOF
+done
+
+# Generate injected initrd
+iasl ./*dsl
+mkdir -p kernel/firmware/acpi/
+rm -f kernel/firmware/acpi/*.aml hmat-initramfs
+cp ./*aml kernel/firmware/acpi/
+find kernel | cpio -c -o > hmat-initramfs
+cat "/boot/initramfs-${KERNEL}.img" >> hmat-initramfs
+
+# Build and evaluate QEMU command line
+QEMU="qemu-system-x86_64 -m ${QEMU_MEM} -smp 8,sockets=${INITIATORS},maxcpus=8 -machine pc,accel=kvm "
+QEMU+="-enable-kvm -display none -nographic -snapshot -hda ${ROOT_IMAGE} "
+QEMU+="-kernel /boot/vmlinuz-${KERNEL} -initrd ./hmat-initramfs "
+QEMU+="-append \"console=tty0 console=ttyS0 root=/dev/sda rw\" "
+
+for i in $(seq 0 $((TARGETS - 1))); do
+ QEMU+="-object memory-backend-file,id=mem${i},share,mem-path=dimm-${i},size=${TARGET_SIZE_MB}M "
+ QEMU+="-numa node,nodeid=${i},memdev=mem${i} "
+done
+
+eval "${QEMU}"
--
2.20.1
3 years, 1 month
[PATCH v2] drivers/dax: Allow to include DEV_DAX_PMEM as builtin
by Aneesh Kumar K.V
This move the dependency to DEV_DAX_PMEM_COMPAT such that only
if DEV_DAX_PMEM is built as module we can allow the compat support.
This allows to test the new code easily in a emulation setup where we
often build things without module support.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar(a)linux.ibm.com>
---
Changes from V1:
* Make sure we only build compat code as module
drivers/dax/Kconfig | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index 5ef624fe3934..a59f338f520f 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -23,7 +23,6 @@ config DEV_DAX
config DEV_DAX_PMEM
tristate "PMEM DAX: direct access to persistent memory"
depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX
- depends on m # until we can kill DEV_DAX_PMEM_COMPAT
default DEV_DAX
help
Support raw access to persistent memory. Note that this
@@ -50,7 +49,7 @@ config DEV_DAX_KMEM
config DEV_DAX_PMEM_COMPAT
tristate "PMEM DAX: support the deprecated /sys/class/dax interface"
- depends on DEV_DAX_PMEM
+ depends on m && DEV_DAX_PMEM=m
default DEV_DAX_PMEM
help
Older versions of the libdaxctl library expect to find all
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.4 04/14] libnvdimm/btt: Fix a kmemdup failure check
by Sasha Levin
From: Aditya Pakki <pakki001(a)umn.edu>
[ Upstream commit 486fa92df4707b5df58d6508728bdb9321a59766 ]
In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.
Signed-off-by: Aditya Pakki <pakki001(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index cb477518dd0e..4c129450495d 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -170,14 +170,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
- if (nd_btt->id < 0) {
- kfree(nd_btt);
- return NULL;
- }
+ if (nd_btt->id < 0)
+ goto out_nd_btt;
nd_btt->lbasize = lbasize;
- if (uuid)
+ if (uuid) {
uuid = kmemdup(uuid, 16, GFP_KERNEL);
+ if (!uuid)
+ goto out_put_id;
+ }
nd_btt->uuid = uuid;
dev = &nd_btt->dev;
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
@@ -192,6 +193,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
}
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)
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.9 06/25] libnvdimm/btt: Fix a kmemdup failure check
by Sasha Levin
From: Aditya Pakki <pakki001(a)umn.edu>
[ Upstream commit 486fa92df4707b5df58d6508728bdb9321a59766 ]
In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.
Signed-off-by: Aditya Pakki <pakki001(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 97dd2925ed6e..5d2c76682848 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -190,14 +190,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
- if (nd_btt->id < 0) {
- kfree(nd_btt);
- return NULL;
- }
+ if (nd_btt->id < 0)
+ goto out_nd_btt;
nd_btt->lbasize = lbasize;
- if (uuid)
+ if (uuid) {
uuid = kmemdup(uuid, 16, GFP_KERNEL);
+ if (!uuid)
+ goto out_put_id;
+ }
nd_btt->uuid = uuid;
dev = &nd_btt->dev;
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
@@ -212,6 +213,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
}
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)
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.9 02/25] libnvdimm/namespace: Fix a potential NULL pointer dereference
by Sasha Levin
From: Kangjie Lu <kjlu(a)umn.edu>
[ Upstream commit 55c1fc0af29a6c1b92f217b7eb7581a882e0c07c ]
In case kmemdup fails, the fix goes to blk_err to avoid NULL
pointer dereference.
Signed-off-by: Kangjie Lu <kjlu(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/namespace_devs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 9bc5f555ee68..cf4a90b50f8b 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2028,9 +2028,12 @@ struct device *create_namespace_blk(struct nd_region *nd_region,
if (!nsblk->uuid)
goto blk_err;
memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
- if (name[0])
+ if (name[0]) {
nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
GFP_KERNEL);
+ if (!nsblk->alt_name)
+ goto blk_err;
+ }
res = nsblk_add_resource(nd_region, ndd, nsblk,
__le64_to_cpu(nd_label->dpa));
if (!res)
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.14 06/95] libnvdimm/btt: Fix a kmemdup failure check
by Sasha Levin
From: Aditya Pakki <pakki001(a)umn.edu>
[ Upstream commit 486fa92df4707b5df58d6508728bdb9321a59766 ]
In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.
Signed-off-by: Aditya Pakki <pakki001(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index d58925295aa7..e610dd890263 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -190,14 +190,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
- if (nd_btt->id < 0) {
- kfree(nd_btt);
- return NULL;
- }
+ if (nd_btt->id < 0)
+ goto out_nd_btt;
nd_btt->lbasize = lbasize;
- if (uuid)
+ if (uuid) {
uuid = kmemdup(uuid, 16, GFP_KERNEL);
+ if (!uuid)
+ goto out_put_id;
+ }
nd_btt->uuid = uuid;
dev = &nd_btt->dev;
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
@@ -212,6 +213,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
}
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)
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.14 02/95] libnvdimm/namespace: Fix a potential NULL pointer dereference
by Sasha Levin
From: Kangjie Lu <kjlu(a)umn.edu>
[ Upstream commit 55c1fc0af29a6c1b92f217b7eb7581a882e0c07c ]
In case kmemdup fails, the fix goes to blk_err to avoid NULL
pointer dereference.
Signed-off-by: Kangjie Lu <kjlu(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/namespace_devs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 50b01d3eadd9..e3f228af59d1 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2234,9 +2234,12 @@ struct device *create_namespace_blk(struct nd_region *nd_region,
if (!nsblk->uuid)
goto blk_err;
memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
- if (name[0])
+ if (name[0]) {
nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
GFP_KERNEL);
+ if (!nsblk->alt_name)
+ goto blk_err;
+ }
res = nsblk_add_resource(nd_region, ndd, nsblk,
__le64_to_cpu(nd_label->dpa));
if (!res)
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.19 17/81] libnvdimm/pmem: fix a possible OOB access when read and write pmem
by Sasha Levin
From: Li RongQing <lirongqing(a)baidu.com>
[ Upstream commit 9dc6488e84b0f64df17672271664752488cd6a25 ]
If offset is not zero and length is bigger than PAGE_SIZE,
this will cause to out of boundary access to a page memory
Fixes: 98cc093cba1e ("block, THP: make block_device_operations.rw_page support THP")
Co-developed-by: Liang ZhiCheng <liangzhicheng(a)baidu.com>
Signed-off-by: Liang ZhiCheng <liangzhicheng(a)baidu.com>
Signed-off-by: Li RongQing <lirongqing(a)baidu.com>
Reviewed-by: Ira Weiny <ira.weiny(a)intel.com>
Reviewed-by: Jeff Moyer <jmoyer(a)redhat.com>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/pmem.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 1d432c5ed275..cff027fc2676 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -113,13 +113,13 @@ static void write_pmem(void *pmem_addr, struct page *page,
while (len) {
mem = kmap_atomic(page);
- chunk = min_t(unsigned int, len, PAGE_SIZE);
+ chunk = min_t(unsigned int, len, PAGE_SIZE - off);
memcpy_flushcache(pmem_addr, mem + off, chunk);
kunmap_atomic(mem);
len -= chunk;
off = 0;
page++;
- pmem_addr += PAGE_SIZE;
+ pmem_addr += chunk;
}
}
@@ -132,7 +132,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
while (len) {
mem = kmap_atomic(page);
- chunk = min_t(unsigned int, len, PAGE_SIZE);
+ chunk = min_t(unsigned int, len, PAGE_SIZE - off);
rem = memcpy_mcsafe(mem + off, pmem_addr, chunk);
kunmap_atomic(mem);
if (rem)
@@ -140,7 +140,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
len -= chunk;
off = 0;
page++;
- pmem_addr += PAGE_SIZE;
+ pmem_addr += chunk;
}
return BLK_STS_OK;
}
--
2.20.1
3 years, 1 month
[PATCH AUTOSEL 4.19 09/81] libnvdimm/btt: Fix a kmemdup failure check
by Sasha Levin
From: Aditya Pakki <pakki001(a)umn.edu>
[ Upstream commit 486fa92df4707b5df58d6508728bdb9321a59766 ]
In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.
Signed-off-by: Aditya Pakki <pakki001(a)umn.edu>
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 795ad4ff35ca..e341498876ca 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -190,14 +190,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
- if (nd_btt->id < 0) {
- kfree(nd_btt);
- return NULL;
- }
+ if (nd_btt->id < 0)
+ goto out_nd_btt;
nd_btt->lbasize = lbasize;
- if (uuid)
+ if (uuid) {
uuid = kmemdup(uuid, 16, GFP_KERNEL);
+ if (!uuid)
+ goto out_put_id;
+ }
nd_btt->uuid = uuid;
dev = &nd_btt->dev;
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
@@ -212,6 +213,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
return NULL;
}
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)
--
2.20.1
3 years, 1 month