Skip to content

Commit e837d83

Browse files
bvanasschegregkh
authored andcommitted
locking/mutex: Introduce mutex_init_with_key()
The following pattern occurs 5 times in kernel drivers: lockdep_register_key(key); __mutex_init(mutex, name, key); In several cases the 'name' argument matches #mutex. Hence, introduce the mutex_init_with_key() macro. This macro derives the 'name' argument from the 'mutex' argument. Suggested-by: Andy Shevchenko <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 96f8052 commit e837d83

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/linux/mutex.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ do { \
6464
__mutex_init((mutex), #mutex, &__key); \
6565
} while (0)
6666

67+
/**
68+
* mutex_init_with_key - initialize a mutex with a given lockdep key
69+
* @mutex: the mutex to be initialized
70+
* @key: the lockdep key to be associated with the mutex
71+
*
72+
* Initialize the mutex to the unlocked state.
73+
*
74+
* It is not allowed to initialize an already locked mutex.
75+
*/
76+
#define mutex_init_with_key(mutex, key) __mutex_init((mutex), #mutex, (key))
77+
6778
#ifndef CONFIG_PREEMPT_RT
6879
#define __MUTEX_INITIALIZER(lockname) \
6980
{ .owner = ATOMIC_LONG_INIT(0) \

0 commit comments

Comments
 (0)