[PATCH] mutex: fix comma placement in mutex initializers
From: Alexey Dobriyan
Date: Mon Jun 24 2024 - 16:35:45 EST
Move the commas in initializer macros _after_ initializer itself,
so they become disentagled from each other.
C99 initializer clause starts with .identifier and ends
with optional comma.
Trailing comma in ifdeffed initializers should be mandatory,
so that following snippet works:
__DEP_MAP_MUTEX_INITIALIZER(lockname)
.bar = 2,
Leading comma should not exist, so that following snippet works:
.foo = 1,
__DEP_MAP_MUTEX_INITIALIZER(lockname)
.bar = 2,
In other words, conditional initializers should be written as
#ifdef CONFIG_FOO
#define INIT_X(val) .x = val,
#else
#define INIT_X(val)
#endif
otherwise it is possible to construct an example which won't compile.
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
include/linux/mutex.h | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -26,10 +26,10 @@ struct device;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
- , .dep_map = { \
+ .dep_map = { \
.name = #lockname, \
.wait_type_inner = LD_WAIT_SLEEP, \
- }
+ },
#else
# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
#endif
@@ -37,7 +37,7 @@ struct device;
#ifdef CONFIG_DEBUG_MUTEXES
# define __DEBUG_MUTEX_INITIALIZER(lockname) \
- , .magic = &lockname
+ .magic = &lockname,
extern void mutex_destroy(struct mutex *lock);
@@ -65,12 +65,14 @@ do { \
__mutex_init((mutex), #mutex, &__key); \
} while (0)
-#define __MUTEX_INITIALIZER(lockname) \
- { .owner = ATOMIC_LONG_INIT(0) \
- , .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
- , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
- __DEBUG_MUTEX_INITIALIZER(lockname) \
- __DEP_MAP_MUTEX_INITIALIZER(lockname) }
+#define __MUTEX_INITIALIZER(lockname) \
+{ \
+ .owner = ATOMIC_LONG_INIT(0), \
+ .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(lockname.wait_lock), \
+ .wait_list = LIST_HEAD_INIT(lockname.wait_list), \
+ __DEBUG_MUTEX_INITIALIZER(lockname) \
+ __DEP_MAP_MUTEX_INITIALIZER(lockname) \
+}
#define DEFINE_MUTEX(mutexname) \
struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
@@ -93,7 +95,7 @@ extern bool mutex_is_locked(struct mutex *lock);
#define __MUTEX_INITIALIZER(mutexname) \
{ \
- .rtmutex = __RT_MUTEX_BASE_INITIALIZER(mutexname.rtmutex) \
+ .rtmutex = __RT_MUTEX_BASE_INITIALIZER(mutexname.rtmutex), \
__DEP_MAP_MUTEX_INITIALIZER(mutexname) \
}