All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nvmet: preserve device path on allocation failure.
@ 2026-09-08  3:35 Julian Sun
  2026-09-08  3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Julian Sun @ 2026-09-08  3:35 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, kch, armenx.baloyan, james.p.freyensee, ming.l

nvmet_ns_device_path_store() frees the old path before allocating its
replacement, losing the existing configuration if allocation fails.
Allocate the new path before freeing the old one.

Fixes: a07b4970f464 ("nvmet: add a generic NVMe target")
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
 drivers/nvme/target/configfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 413ee2d16d29..37998bb91408 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -534,6 +534,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
 	struct nvmet_subsys *subsys = ns->subsys;
 	size_t len;
 	int ret;
+	char *new_path = NULL;
 
 	mutex_lock(&subsys->lock);
 	ret = -EBUSY;
@@ -545,12 +546,14 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
 	if (!len)
 		goto out_unlock;
 
-	kfree(ns->device_path);
 	ret = -ENOMEM;
-	ns->device_path = kmemdup_nul(page, len, GFP_KERNEL);
-	if (!ns->device_path)
+	new_path = kmemdup_nul(page, len, GFP_KERNEL);
+	if (!new_path)
 		goto out_unlock;
 
+	kfree(ns->device_path);
+	ns->device_path = new_path;
+
 	mutex_unlock(&subsys->lock);
 	return count;
 
-- 
2.39.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-09-11 14:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08  3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
2026-09-08  3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
2026-09-10  5:42   ` Christoph Hellwig
2026-09-10  5:47     ` Julian Sun
2026-09-10  5:25 ` [PATCH 1/2] nvmet: preserve device path on allocation failure Christoph Hellwig
2026-09-10  5:35   ` Julian Sun
2026-09-10  5:37     ` Christoph Hellwig
2026-09-10  5:42 ` Christoph Hellwig
2026-09-11 14:45 ` Keith Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.