linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: kernel-team@android.com, Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH] bitops: Move test_bit() into bitops/atomic.h
Date: Thu, 21 May 2020 15:31:29 +0100	[thread overview]
Message-ID: <20200521143129.7526-1-will@kernel.org> (raw)

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@infradead.org>
Signed-off-by: Will Deacon <will@kernel.org>
---
 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


             reply	other threads:[~2020-05-21 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 14:31 Will Deacon [this message]
2020-05-22 11:10 ` [PATCH] bitops: Move test_bit() into bitops/atomic.h kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200521143129.7526-1-will@kernel.org \
    --to=will@kernel.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).