[PATCHv2 09/17] nvme: add Clang context annotations for nvme_subsystems_lock

Nilay Shroff nilay at linux.ibm.com
Fri Jun 26 07:48:55 PDT 2026


On 6/26/26 12:15 PM, Christoph Hellwig wrote:
>> -static LIST_HEAD(nvme_subsystems);
>> +static __guarded_by(&nvme_subsystems_lock) LIST_HEAD(nvme_subsystems);
> 
> Having the guard_by before the LIST_HEAD makes this a real mess to
> read.
> 
> Can we add a
> 
> #define LIST_HEAD_GUARDED(_list, _lock) \
> 	__guarded_by(_lock) LIST_HEAD(_list)
> 
> and use that instead?  And maybe do these after the lock declaration.
> While the compiler doesn't care, that's much easier to follow for
> humans.
> 
Makes sense. Will add this helper macro in next patchset.

>> +	/*
>> +	 * Initializing subsys->ctrls list doesn't need to be protected
>> +	 * using @nvme_subsystems_lock. So suppress the Clang's warning
>> +	 * declaring context_unsafe.
>> +	 */
>> +	context_unsafe(INIT_LIST_HEAD(&subsys->ctrls));
> 
> This could also use a helper.
> 
Maybe INIT_LIST_HEAD_UNSAFE() helper as I suggested in the earlier
message ?

BTW, I think these helpers should be added in include/linux/list.h so
it will be helpful in general for other kernel code as well.

Thanks,
--Nilay



More information about the Linux-nvme mailing list