All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rwsem: fix commas in initialisation
@ 2020-07-11 14:59 Alexey Dobriyan
  2020-07-13 11:51 ` Peter Zijlstra
  2020-07-17 11:22 ` [tip: locking/core] " tip-bot2 for Alexey Dobriyan
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2020-07-11 14:59 UTC (permalink / raw)
  To: peterz, mingo, will; +Cc: linux-kernel

Leading comma prevents arbitrary reordering of initialisation clauses.
The whole point of C99 initialisation is to allow any such reordering.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/linux/rwsem.h |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -66,22 +66,22 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define __RWSEM_DEP_MAP_INIT(lockname)			\
-	, .dep_map = {					\
+	.dep_map = {					\
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_SLEEP,	\
-	}
+	},
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
 #endif
 
 #ifdef CONFIG_DEBUG_RWSEMS
-# define __DEBUG_RWSEM_INITIALIZER(lockname) , .magic = &lockname
+# define __DEBUG_RWSEM_INITIALIZER(lockname) .magic = &lockname,
 #else
 # define __DEBUG_RWSEM_INITIALIZER(lockname)
 #endif
 
 #ifdef CONFIG_RWSEM_SPIN_ON_OWNER
-#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED
+#define __RWSEM_OPT_INIT(lockname) .osq = OSQ_LOCK_UNLOCKED,
 #else
 #define __RWSEM_OPT_INIT(lockname)
 #endif
@@ -90,7 +90,7 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
 	{ __RWSEM_INIT_COUNT(name),				\
 	  .owner = ATOMIC_LONG_INIT(0),				\
 	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
-	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock)	\
+	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
 	  __RWSEM_OPT_INIT(name)				\
 	  __DEBUG_RWSEM_INITIALIZER(name)			\
 	  __RWSEM_DEP_MAP_INIT(name) }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rwsem: fix commas in initialisation
  2020-07-11 14:59 [PATCH] rwsem: fix commas in initialisation Alexey Dobriyan
@ 2020-07-13 11:51 ` Peter Zijlstra
  2020-07-13 14:06   ` Alexey Dobriyan
  2020-07-17 11:22 ` [tip: locking/core] " tip-bot2 for Alexey Dobriyan
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2020-07-13 11:51 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: mingo, will, linux-kernel

On Sat, Jul 11, 2020 at 05:59:54PM +0300, Alexey Dobriyan wrote:
> Leading comma prevents arbitrary reordering of initialisation clauses.
> The whole point of C99 initialisation is to allow any such reordering.

I'm conflicted on this argument, the only reason I'd be inclined to take
this patch is that it allows fixing the initialization order to not be
random.

That is, I'd fold in the below.

--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -89,9 +89,9 @@ static inline int rwsem_is_locked(struct
 #define __RWSEM_INITIALIZER(name)				\
 	{ __RWSEM_INIT_COUNT(name),				\
 	  .owner = ATOMIC_LONG_INIT(0),				\
-	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
-	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
 	  __RWSEM_OPT_INIT(name)				\
+	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
+	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
 	  __DEBUG_RWSEM_INITIALIZER(name)			\
 	  __RWSEM_DEP_MAP_INIT(name) }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rwsem: fix commas in initialisation
  2020-07-13 11:51 ` Peter Zijlstra
@ 2020-07-13 14:06   ` Alexey Dobriyan
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2020-07-13 14:06 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: mingo, will, linux-kernel

On Mon, Jul 13, 2020 at 01:51:41PM +0200, Peter Zijlstra wrote:
> On Sat, Jul 11, 2020 at 05:59:54PM +0300, Alexey Dobriyan wrote:
> > Leading comma prevents arbitrary reordering of initialisation clauses.
> > The whole point of C99 initialisation is to allow any such reordering.
> 
> I'm conflicted on this argument, the only reason I'd be inclined to take
> this patch is that it allows fixing the initialization order to not be
> random.

Yes, this is how the issue was noticed.

> That is, I'd fold in the below.
> 
> --- a/include/linux/rwsem.h
> +++ b/include/linux/rwsem.h
> @@ -89,9 +89,9 @@ static inline int rwsem_is_locked(struct
>  #define __RWSEM_INITIALIZER(name)				\
>  	{ __RWSEM_INIT_COUNT(name),				\
>  	  .owner = ATOMIC_LONG_INIT(0),				\
> -	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
> -	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
>  	  __RWSEM_OPT_INIT(name)				\
> +	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
> +	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\

One less chunk to compile with g++, a billion to go :^)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: locking/core] rwsem: fix commas in initialisation
  2020-07-11 14:59 [PATCH] rwsem: fix commas in initialisation Alexey Dobriyan
  2020-07-13 11:51 ` Peter Zijlstra
@ 2020-07-17 11:22 ` tip-bot2 for Alexey Dobriyan
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Alexey Dobriyan @ 2020-07-17 11:22 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Alexey Dobriyan, Peter Zijlstra (Intel), x86, LKML

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     a9232dc5607dbada801f2fe83ea307cda762969a
Gitweb:        https://git.kernel.org/tip/a9232dc5607dbada801f2fe83ea307cda762969a
Author:        Alexey Dobriyan <adobriyan@gmail.com>
AuthorDate:    Sat, 11 Jul 2020 17:59:54 +03:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 16 Jul 2020 23:19:51 +02:00

rwsem: fix commas in initialisation

Leading comma prevents arbitrary reordering of initialisation clauses.
The whole point of C99 initialisation is to allow any such reordering.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200711145954.GA1178171@localhost.localdomain
---
 include/linux/rwsem.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 7e5b2a4..25e3fde 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -60,39 +60,39 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
 }
 
 #define RWSEM_UNLOCKED_VALUE		0L
-#define __RWSEM_INIT_COUNT(name)	.count = ATOMIC_LONG_INIT(RWSEM_UNLOCKED_VALUE)
+#define __RWSEM_COUNT_INIT(name)	.count = ATOMIC_LONG_INIT(RWSEM_UNLOCKED_VALUE)
 
 /* Common initializer macros and functions */
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define __RWSEM_DEP_MAP_INIT(lockname)			\
-	, .dep_map = {					\
+	.dep_map = {					\
 		.name = #lockname,			\
 		.wait_type_inner = LD_WAIT_SLEEP,	\
-	}
+	},
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
 #endif
 
 #ifdef CONFIG_DEBUG_RWSEMS
-# define __DEBUG_RWSEM_INITIALIZER(lockname) , .magic = &lockname
+# define __RWSEM_DEBUG_INIT(lockname) .magic = &lockname,
 #else
-# define __DEBUG_RWSEM_INITIALIZER(lockname)
+# define __RWSEM_DEBUG_INIT(lockname)
 #endif
 
 #ifdef CONFIG_RWSEM_SPIN_ON_OWNER
-#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED
+#define __RWSEM_OPT_INIT(lockname) .osq = OSQ_LOCK_UNLOCKED,
 #else
 #define __RWSEM_OPT_INIT(lockname)
 #endif
 
 #define __RWSEM_INITIALIZER(name)				\
-	{ __RWSEM_INIT_COUNT(name),				\
+	{ __RWSEM_COUNT_INIT(name),				\
 	  .owner = ATOMIC_LONG_INIT(0),				\
-	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
-	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock)	\
 	  __RWSEM_OPT_INIT(name)				\
-	  __DEBUG_RWSEM_INITIALIZER(name)			\
+	  .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock),\
+	  .wait_list = LIST_HEAD_INIT((name).wait_list),	\
+	  __RWSEM_DEBUG_INIT(name)				\
 	  __RWSEM_DEP_MAP_INIT(name) }
 
 #define DECLARE_RWSEM(name) \

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-17 11:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11 14:59 [PATCH] rwsem: fix commas in initialisation Alexey Dobriyan
2020-07-13 11:51 ` Peter Zijlstra
2020-07-13 14:06   ` Alexey Dobriyan
2020-07-17 11:22 ` [tip: locking/core] " tip-bot2 for Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.