lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date: Mon, 24 Jun 2024 23:35:33 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
	Will Deacon <will@...nel.org>, Waiman Long <longman@...hat.com>
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] mutex: fix comma placement in mutex initializers

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@...il.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)				\
 }
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ