Re: [PATCH 07/15] nvme: add Clang context annotations for nvme_subsystem::lock
From: Nilay Shroff
Date: Thu Jun 11 2026 - 00:36:42 EST
On 6/10/26 9:58 PM, Bart Van Assche wrote:
On 6/10/26 7:27 AM, Nilay Shroff wrote:
+ mutex_lock(&ctrl->subsys->lock);
list_add_tail(&head->entry, &ctrl->subsys->nsheads);
+ mutex_unlock(&ctrl->subsys->lock);
Has it been considered to use scoped_guard()?
Yes, scoped_guard() would work here. However, my preference is
to use the guard helpers primarily for object initialization,
where they create a temporary synthetic acquire/release pattern
that helps Clang's context analysis understand accesses to newly
initialized objects.
In this case, we are simply protecting a list update with a
straightforward lock/unlock pair. I find the explicit locking
pattern a bit more intuitive and easier to follow here, since
the locking scope is small and there are no early returns or
error paths that would particularly benefit from scoped_guard().
Thanks,
--Nilay