[PATCH v8 08/31] locking/spinlock: introduce `_raw_spin_lock_init`

Miguel Ojeda posted 31 patches 3 years, 8 months ago
There is a newer version of this series
[PATCH v8 08/31] locking/spinlock: introduce `_raw_spin_lock_init`
Posted by Miguel Ojeda 3 years, 8 months ago
From: Wedson Almeida Filho <wedsonaf@google.com>

A Rust helper (introduced in a later patch) needs to call
`raw_spin_lock_init` with a passed key, rather than define
one in place.

In order to do that, this changes the `raw_spin_lock_init` macro
to call a new `_raw_spin_lock_init` function which takes the key
as an extra parameter.

Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 include/linux/spinlock.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index ad1c91884ed8..27df5380c1e4 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -99,11 +99,17 @@
   extern void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
 				   struct lock_class_key *key, short inner);
 
+static inline void _raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
+				       struct lock_class_key *key)
+{
+	__raw_spin_lock_init(lock, name, key, LD_WAIT_SPIN);
+}
+
 # define raw_spin_lock_init(lock)					\
 do {									\
 	static struct lock_class_key __key;				\
 									\
-	__raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN);	\
+	_raw_spin_lock_init((lock), #lock, &__key);			\
 } while (0)
 
 #else
-- 
2.37.1
Re: [PATCH v8 08/31] locking/spinlock: introduce `_raw_spin_lock_init`
Posted by Boqun Feng 3 years, 8 months ago
On Tue, Aug 02, 2022 at 03:49:55AM +0200, Miguel Ojeda wrote:
> From: Wedson Almeida Filho <wedsonaf@google.com>
> 
> A Rust helper (introduced in a later patch) needs to call
> `raw_spin_lock_init` with a passed key, rather than define
> one in place.
> 
> In order to do that, this changes the `raw_spin_lock_init` macro
> to call a new `_raw_spin_lock_init` function which takes the key
> as an extra parameter.
> 
> Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
> Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
> Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Acked-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> ---
>  include/linux/spinlock.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
> index ad1c91884ed8..27df5380c1e4 100644
> --- a/include/linux/spinlock.h
> +++ b/include/linux/spinlock.h
> @@ -99,11 +99,17 @@
>    extern void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
>  				   struct lock_class_key *key, short inner);
>  
> +static inline void _raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
> +				       struct lock_class_key *key)
> +{
> +	__raw_spin_lock_init(lock, name, key, LD_WAIT_SPIN);
> +}
> +
>  # define raw_spin_lock_init(lock)					\
>  do {									\
>  	static struct lock_class_key __key;				\
>  									\
> -	__raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN);	\
> +	_raw_spin_lock_init((lock), #lock, &__key);			\
>  } while (0)
>  
>  #else
> -- 
> 2.37.1
> 
>