[PATCH] bitops: Move test_bit() into bitops/atomic.h

From: Will Deacon
Date: Thu May 21 2020 - 10:31:39 EST


test_bit() is an atomic operation as documented by atomic_bitops.txt.
Move the function from bitops/non-atomic.h to bitops/atomic.h and adjust
its implementation to align with the other atomic bitops.

Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Will Deacon <will@xxxxxxxxxx>
---
include/asm-generic/bitops/atomic.h | 6 ++++++
include/asm-generic/bitops/non-atomic.h | 10 ----------
2 files changed, 6 insertions(+), 10 deletions(-)

Just found this kicking around on a branch from last year!

diff --git a/include/asm-generic/bitops/atomic.h b/include/asm-generic/bitops/atomic.h
index dd90c9792909..5fc4399d8fb4 100644
--- a/include/asm-generic/bitops/atomic.h
+++ b/include/asm-generic/bitops/atomic.h
@@ -17,6 +17,12 @@ static inline void set_bit(unsigned int nr, volatile unsigned long *p)
atomic_long_or(BIT_MASK(nr), (atomic_long_t *)p);
}

+static inline int test_bit(unsigned int nr, const volatile unsigned long *p)
+{
+ p += BIT_WORD(nr);
+ return !!(READ_ONCE(*p) & BIT_MASK(nr));
+}
+
static inline void clear_bit(unsigned int nr, volatile unsigned long *p)
{
p += BIT_WORD(nr);
diff --git a/include/asm-generic/bitops/non-atomic.h b/include/asm-generic/bitops/non-atomic.h
index 7e10c4b50c5d..8b44da59a9d0 100644
--- a/include/asm-generic/bitops/non-atomic.h
+++ b/include/asm-generic/bitops/non-atomic.h
@@ -96,14 +96,4 @@ static inline int __test_and_change_bit(int nr,
return (old & mask) != 0;
}

-/**
- * test_bit - Determine whether a bit is set
- * @nr: bit number to test
- * @addr: Address to start counting from
- */
-static inline int test_bit(int nr, const volatile unsigned long *addr)
-{
- return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
-}
-
#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
--
2.26.2.761.g0e0b3e54be-goog