* [PATCH] mutex: fix comma placement in mutex initializers
@ 2024-06-24 20:35 Alexey Dobriyan
0 siblings, 0 replies; only message in thread
From: Alexey Dobriyan @ 2024-06-24 20:35 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long; +Cc: linux-kernel
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@gmail.com>
---
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) \
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-06-24 20:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-24 20:35 [PATCH] mutex: fix comma placement in mutex initializers Alexey Dobriyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®