Skip to contentSkip to conversation

libnvdimm, namespace: check nsblk->uuid immediately after its allocation

PATCH In review Wei Yang 2 participants 4 messages Jan 16, 2019 – Jun 26, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 libnvdimm, namespace: check nsblk->uuid immediately after its allocation

When creating nd_namespace_blk, its uuid is copied from nd_label->uuid. In case the memory allocation fails, it goes to the error branch.

This check is better to be done immediately after memory allocation, while current implementation does this after assigning claim_class.

This patch moves the check immediately after uuid allocation.

---
 drivers/nvdimm/namespace_devs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvdimm/namespace_devs.c +2 -2
index 681af3a8fd62..9471b9ca04f5 100644
@@ -2240,11 +2240,11 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
 	nsblk->lbasize = __le64_to_cpu(nd_label->lbasize);
 	nsblk->uuid = kmemdup(nd_label->uuid, NSLABEL_UUID_LEN,
 			GFP_KERNEL);
+	if (!nsblk->uuid)
+		goto blk_err;
 	if (namespace_label_has(ndd, abstraction_guid))
 		nsblk->common.claim_class
 			= to_nvdimm_cclass(&nd_label->abstraction_guid);
-	if (!nsblk->uuid)
-		goto blk_err;
 	memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
 	if (name[0])
 		nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
Signature · 6 lines
2.19.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author
#1 lore raw

Hi, Dan

Do you have some time on this?

Quoted 33 lines · Wei Yang

When creating nd_namespace_blk, its uuid is copied from nd_label->uuid. In case the memory allocation fails, it goes to the error branch.

This check is better to be done immediately after memory allocation, while current implementation does this after assigning claim_class.

This patch moves the check immediately after uuid allocation.

---
drivers/nvdimm/namespace_devs.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvdimm/namespace_devs.c +2 -2
index 681af3a8fd62..9471b9ca04f5 100644
@@ -2240,11 +2240,11 @@ static struct device *create_namespace_blk(struct nd_region *nd_region,
 	nsblk->lbasize = __le64_to_cpu(nd_label->lbasize);
 	nsblk->uuid = kmemdup(nd_label->uuid, NSLABEL_UUID_LEN,
 			GFP_KERNEL);
+	if (!nsblk->uuid)
+		goto blk_err;
 	if (namespace_label_has(ndd, abstraction_guid))
 		nsblk->common.claim_class
 			= to_nvdimm_cclass(&nd_label->abstraction_guid);
-	if (!nsblk->uuid)
-		goto blk_err;
 	memcpy(name, nd_label->name, NSLABEL_NAME_LEN);
 	if (name[0])
 		nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN,
Signature · 1 line
2.19.1
Signature · 6 lines
Wei Yang
Help you, Help me
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#2 lore raw
Quoted 13 lines · Wei Yang

Hi, Dan

Do you have some time on this?

Quoted 7 lines · Wei Yang

When creating nd_namespace_blk, its uuid is copied from nd_label->uuid. In case the memory allocation fails, it goes to the error branch.

This check is better to be done immediately after memory allocation, while current implementation does this after assigning claim_class.

This patch moves the check immediately after uuid allocation.

This looks ok, but the patch has no significant impact. I'm not particularly motivated to carry it forward.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#3 lore raw
Quoted 10 lines · Dan Williams
Quoted 9 lines · Wei Yang

Hi, Dan

Do you have some time on this?

Quoted 3 lines · Wei Yang

When creating nd_namespace_blk, its uuid is copied from nd_label->uuid. In case the memory allocation fails, it goes to the error branch.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

This check is better to be done immediately after memory allocation, while current implementation does this after assigning claim_class.

This patch moves the check immediately after uuid allocation.

This looks ok, but the patch has no significant impact. I'm not particularly motivated to carry it forward.

Got it. Thanks

Signature · 6 lines
Wei Yang
Help you, Help me
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm