lib: sbi_locks: annotate spinlock APIs for TSA

Add Thread Safety Analysis (TSA) annotations for spinlock APIs, allowing
the compiler to reason about lock acquisition and release.

Annotations have a different meaning if used in header declarations vs C
file implementations. In header declarations, they specify the semantics
of the given function, meaning that we must specify that the spinlock
functions acquire and release a lock ("capability" in clang terms).
In function implementations, attributes affect the function body and
callers in the same translation unit; since the spinlock functions
contain inline assembly, they must be excluded from analysis.

Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260909162322.29778-4-carlos.lopezr4096@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Carlos López
2026-09-16 09:48:30 +05:30
committed by Anup Patel
parent 8d109c7e87
commit b8f7e9ea80
2 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -45,7 +45,7 @@ bool spin_trylock(spinlock_t *lock)
return l0 == 0;
}
void spin_lock(spinlock_t *lock)
void spin_lock(spinlock_t *lock) NO_THREAD_SAFETY_ANALYSIS
{
unsigned long inc = 1u << TICKET_SHIFT;
unsigned long mask = 0xffffu;
@@ -84,7 +84,7 @@ void spin_lock(spinlock_t *lock)
: "memory");
}
void spin_unlock(spinlock_t *lock)
void spin_unlock(spinlock_t *lock) NO_THREAD_SAFETY_ANALYSIS
{
__smp_store_release(&lock->owner, lock->owner + 1);
}