Re: [PATCH v3] coccinelle: locks: Add must_hold.cocci

From: Bart Van Assche

Date: Mon Nov 23 2026 - 11:26:07 EST


On 11/23/26 2:45 AM, Marco Elver wrote:
Clang's context analysis treats lockdep_assert_held*() as an assumption
that the lock is held. A function that asserts instead of being
annotated with __must_hold() therefore passes the analysis, but its
callers are never checked.

Add a script that reports functions which assert on all paths that a
lock is held, where the lock can be named in a function attribute, and
which are not annotated with __must_hold*(), __releases*(),
__cond_releases*(), __context_unsafe() or __no_context_analysis. A lock
can be named if all identifiers in the lock expression are parameters or
member names, or if it is a global of the form &name or &name.member.
Functions that mention the lock before asserting it, e.g. to acquire it,
are skipped.

Bart Van Assche <bvanassche@xxxxxxx>