OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] lib: sbi: Have spinlock checks return bool
@ 2021-05-13  4:52 Daniel Schaefer
  2021-05-14 11:42 ` Anup Patel
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Schaefer @ 2021-05-13  4:52 UTC (permalink / raw)
  To: opensbi

spin_lock_check already returned bool in the source file but not in the
header. With some toolchains that causes an error, as it should.

Because it and related functions all essentially return a bool, we can
use this opportunity to change them.

Cc: Abner Chang <abner.chang@hpe.com>
Cc: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
---
 include/sbi/riscv_locks.h | 4 ++--
 lib/sbi/riscv_locks.c     | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/sbi/riscv_locks.h b/include/sbi/riscv_locks.h
index 492935f5d60b..38d9cbeb7b2a 100644
--- a/include/sbi/riscv_locks.h
+++ b/include/sbi/riscv_locks.h
@@ -34,9 +34,9 @@ typedef struct {
 #define DEFINE_SPIN_LOCK(x)	\
 	spinlock_t SPIN_LOCK_INIT(x)
 
-int spin_lock_check(spinlock_t *lock);
+bool spin_lock_check(spinlock_t *lock);
 
-int spin_trylock(spinlock_t *lock);
+bool spin_trylock(spinlock_t *lock);
 
 void spin_lock(spinlock_t *lock);
 
diff --git a/lib/sbi/riscv_locks.c b/lib/sbi/riscv_locks.c
index 75b443bd35b8..acab7769240b 100644
--- a/lib/sbi/riscv_locks.c
+++ b/lib/sbi/riscv_locks.c
@@ -8,7 +8,7 @@
 #include <sbi/riscv_barrier.h>
 #include <sbi/riscv_locks.h>
 
-static inline int spin_lock_unlocked(spinlock_t lock)
+static inline bool spin_lock_unlocked(spinlock_t lock)
 {
 	return lock.owner == lock.next;
 }
@@ -19,7 +19,7 @@ bool spin_lock_check(spinlock_t *lock)
 	return !spin_lock_unlocked(*lock);
 }
 
-int spin_trylock(spinlock_t *lock)
+bool spin_trylock(spinlock_t *lock)
 {
 	unsigned long inc = 1u << TICKET_SHIFT;
 	unsigned long mask = 0xffffu << TICKET_SHIFT;
@@ -42,7 +42,7 @@ int spin_trylock(spinlock_t *lock)
 		: "r"(inc), "r"(mask), "I"(TICKET_SHIFT)
 		: "memory");
 
-	return !l0;
+	return l0 == 0;
 }
 
 void spin_lock(spinlock_t *lock)
-- 
2.30.1



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

* [PATCH v1 1/1] lib: sbi: Have spinlock checks return bool
  2021-05-13  4:52 [PATCH v1 1/1] lib: sbi: Have spinlock checks return bool Daniel Schaefer
@ 2021-05-14 11:42 ` Anup Patel
  0 siblings, 0 replies; 2+ messages in thread
From: Anup Patel @ 2021-05-14 11:42 UTC (permalink / raw)
  To: opensbi



> -----Original Message-----
> From: opensbi <opensbi-bounces@lists.infradead.org> On Behalf Of Daniel
> Schaefer
> Sent: 13 May 2021 10:23
> To: opensbi at lists.infradead.org
> Cc: Abner Chang <abner.chang@hpe.com>; Anup Patel
> <Anup.Patel@wdc.com>
> Subject: [PATCH v1 1/1] lib: sbi: Have spinlock checks return bool
> 
> spin_lock_check already returned bool in the source file but not in the
> header. With some toolchains that causes an error, as it should.
> 
> Because it and related functions all essentially return a bool, we can use this
> opportunity to change them.
> 
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Anup Patel <anup.patel@wdc.com>
> Signed-off-by: Daniel Schaefer <git@danielschaefer.me>

Looks good to me.

Reviewed-by: Anup Patel <anup.patel@wdc.com>

Applied this patch to the riscv/opensbi repo

Thanks,
Anup

> ---
>  include/sbi/riscv_locks.h | 4 ++--
>  lib/sbi/riscv_locks.c     | 6 +++---
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/sbi/riscv_locks.h b/include/sbi/riscv_locks.h index
> 492935f5d60b..38d9cbeb7b2a 100644
> --- a/include/sbi/riscv_locks.h
> +++ b/include/sbi/riscv_locks.h
> @@ -34,9 +34,9 @@ typedef struct {
>  #define DEFINE_SPIN_LOCK(x)	\
>  	spinlock_t SPIN_LOCK_INIT(x)
> 
> -int spin_lock_check(spinlock_t *lock);
> +bool spin_lock_check(spinlock_t *lock);
> 
> -int spin_trylock(spinlock_t *lock);
> +bool spin_trylock(spinlock_t *lock);
> 
>  void spin_lock(spinlock_t *lock);
> 
> diff --git a/lib/sbi/riscv_locks.c b/lib/sbi/riscv_locks.c index
> 75b443bd35b8..acab7769240b 100644
> --- a/lib/sbi/riscv_locks.c
> +++ b/lib/sbi/riscv_locks.c
> @@ -8,7 +8,7 @@
>  #include <sbi/riscv_barrier.h>
>  #include <sbi/riscv_locks.h>
> 
> -static inline int spin_lock_unlocked(spinlock_t lock)
> +static inline bool spin_lock_unlocked(spinlock_t lock)
>  {
>  	return lock.owner == lock.next;
>  }
> @@ -19,7 +19,7 @@ bool spin_lock_check(spinlock_t *lock)
>  	return !spin_lock_unlocked(*lock);
>  }
> 
> -int spin_trylock(spinlock_t *lock)
> +bool spin_trylock(spinlock_t *lock)
>  {
>  	unsigned long inc = 1u << TICKET_SHIFT;
>  	unsigned long mask = 0xffffu << TICKET_SHIFT; @@ -42,7 +42,7 @@
> int spin_trylock(spinlock_t *lock)
>  		: "r"(inc), "r"(mask), "I"(TICKET_SHIFT)
>  		: "memory");
> 
> -	return !l0;
> +	return l0 == 0;
>  }
> 
>  void spin_lock(spinlock_t *lock)
> --
> 2.30.1
> 
> 
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi


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

end of thread, other threads:[~2021-05-14 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-13  4:52 [PATCH v1 1/1] lib: sbi: Have spinlock checks return bool Daniel Schaefer
2021-05-14 11:42 ` Anup Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox