[PATCH 12/23] nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lock

Nilay Shroff nilay at linux.ibm.com
Sun Nov 8 19:28:17 PST 2026


The nvmet_ns::uuid field is protected by nvmet_subsys::lock. However,
nvmet_ns_alloc() calls uuid_gen() without holding this lock, triggering
a Clang context analyzer warning:

drivers/nvme/target/core.c:781:16: error: passing pointer to variable 'uuid' requires holding mutex '_res->subsys->lock'
      [-Werror,-Wthread-safety-pointer]
  781 |         uuid_gen(&ns->uuid);
      |                       ^

Fix this by moving the uuid_gen() call into the existing subsys->lock
critical section in nvmet_ns_alloc().

Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
 drivers/nvme/target/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 77e2ef211711..08a70439fd55 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -771,6 +771,7 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid)
 		goto out_exit;
 
 	subsys->nr_namespaces++;
+	uuid_gen(&ns->uuid);
 
 	__release_ctx_lock(&ns->subsys->lock);
 	mutex_unlock(&subsys->lock);
@@ -780,7 +781,6 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid)
 	nvmet_ana_group_enabled[ns->anagrpid]++;
 	up_write(&nvmet_ana_sem);
 
-	uuid_gen(&ns->uuid);
 	ns->buffered_io = false;
 	ns->csi = NVME_CSI_NVM;
 
-- 
2.53.0




More information about the Linux-nvme mailing list