From f550466949e822afcd0b546a4fc35795930660bc Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Wed, 15 Oct 2025 11:05:54 -0400 Subject: locking: Introduce __cleanup() based infrastructure [ Upstream commit 54da6a0924311c7cf5015533991e44fb8eb12773 ] Use __attribute__((__cleanup__(func))) to build: - simple auto-release pointers using __free() - 'classes' with constructor and destructor semantics for scope-based resource management. - lock guards based on the above classes. Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230612093537.614161713%40infradead.org Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/mutex.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/linux/mutex.h') diff --git a/include/linux/mutex.h b/include/linux/mutex.h index 9ef01b9d2456..5b5630e58407 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -19,6 +19,7 @@ #include #include #include +#include struct device; @@ -246,4 +247,7 @@ extern void mutex_unlock(struct mutex *lock); extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock); +DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T)) +DEFINE_FREE(mutex, struct mutex *, if (_T) mutex_unlock(_T)) + #endif /* __LINUX_MUTEX_H */ -- cgit v1.2.3