From f278680a0d4fa20538032390d6d7056f44c6ca40 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 10 Nov 2026 09:13:21 -0800 Subject: [PATCH 2/3] nvme: Pass the subsystem pointer to nvme_find_ns_head() Pass the struct nvme_subsystem pointer directly to nvme_find_ns_head(). Update the __must_hold() annotation and the lockdep assertion to check &subsys->lock instead of &ctrl->subsys->lock, and traverse &subsys->nsheads directly. Notice that nvme_subsystem::nsheads is guarded by &nvme_subsystem::lock. Observe that Clang lock context analysis cannot verify lock requirements when accessing nsheads through the nested pointer ctrl->subsys. Enable the compiler to verify that &subsys->lock is held while traversing &subsys->nsheads by passing the subsystem pointer directly. Fixes: d1fdf49b5f7f ("nvme: add context annotations for nvme_subsystem::lock") Signed-off-by: Bart Van Assche --- drivers/nvme/host/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index def9ac6e8b6a..98c39fef0646 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3910,14 +3910,15 @@ static const struct file_operations nvme_dev_fops = { }; static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, - unsigned nsid) - __must_hold(&ctrl->subsys->lock) + struct nvme_subsystem *subsys, + unsigned nsid) + __must_hold(&subsys->lock) { struct nvme_ns_head *h; - lockdep_assert_held(&ctrl->subsys->lock); + lockdep_assert_held(&subsys->lock); - list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { + list_for_each_entry(h, &subsys->nsheads, entry) { /* * Private namespaces can share NSIDs under some conditions. * In that case we can't use the same ns_head for namespaces @@ -4192,7 +4193,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) } mutex_lock(&ctrl->subsys->lock); - head = nvme_find_ns_head(ctrl, info->nsid); + head = nvme_find_ns_head(ctrl, ctrl->subsys, info->nsid); if (!head) { ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); if (ret) {