From: Alexey Dobriyan <adobriyan@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Waiman Long <longman@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] mutex: fix comma placement in mutex initializers
Date: Mon, 24 Jun 2024 23:35:33 +0300 [thread overview]
Message-ID: <0773b142-4928-401b-a510-462afee0924f@p183> (raw)
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) \
}
reply other threads:[~2024-06-24 20:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0773b142-4928-401b-a510-462afee0924f@p183 \
--to=adobriyan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®