Skip to contentSkip to conversation

nvmet: replace kstrndup() with kmemdup_nul()

PATCH Applied Chen Zhou 2 participants 2 messages May 8, 2020 – May 12, 2020

Subsystems (2)
lore
Share & tools
lore

Chen Zhou

author
#0 lore raw

PATCH 1/1 nvmet: replace kstrndup() with kmemdup_nul()

It is more efficient to use kmemdup_nul() if the size is known exactly.

The doc in kernel:
"Note: Use kmemdup_nul() instead if the size is known exactly."

---
 drivers/nvme/target/configfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/configfs.c +2 -2
index 58cabd7b6fc5..9894668a40e7 100644
@@ -327,7 +327,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
 
 	kfree(ns->device_path);
 	ret = -ENOMEM;
-	ns->device_path = kstrndup(page, len, GFP_KERNEL);
+	ns->device_path = kmemdup_nul(page, len, GFP_KERNEL);
 	if (!ns->device_path)
 		goto out_unlock;
 
@@ -963,7 +963,7 @@ static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
 			return -EINVAL;
 	}
 
-	new_model_number = kstrndup(page, len, GFP_KERNEL);
+	new_model_number = kmemdup_nul(page, len, GFP_KERNEL);
 	if (!new_model_number)
 		return -ENOMEM;
 
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Chen Zhou

It is more efficient to use kmemdup_nul() if the size is known exactly.

The doc in kernel:
"Note: Use kmemdup_nul() instead if the size is known exactly."

Thanks,

applied to nvme-5.8.