From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] bitops: change test_bit return type from int to bool
Date: Mon, 1 Jul 2024 09:35:09 +0200 [thread overview]
Message-ID: <20240701073509.176191-1-a.fatoum@pengutronix.de> (raw)
test_bit currently returns some positive integer on success and don't
enforce the return values to be either false or true.
This can lead to problems if the return value is not used for
truthiness, but in arithmetic.
This seems to be the case only in KASAN code, where it's used to count
errors. Change the return type to fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/bitops.h | 2 +-
include/asm-generic/bitops/ops.h | 2 +-
scripts/include/asm-generic/bitops/atomic.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/bitops.h b/arch/arm/include/asm/bitops.h
index 2d0d300da2eb..8e9e4fc36944 100644
--- a/arch/arm/include/asm/bitops.h
+++ b/arch/arm/include/asm/bitops.h
@@ -72,7 +72,7 @@ static inline int __test_and_change_bit(int nr, volatile void *addr)
/*
* This routine doesn't need to be atomic.
*/
-static inline int test_bit(int nr, const void * addr)
+static inline bool test_bit(int nr, const void * addr)
{
return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7));
}
diff --git a/include/asm-generic/bitops/ops.h b/include/asm-generic/bitops/ops.h
index 1684621922e5..326fe00c017a 100644
--- a/include/asm-generic/bitops/ops.h
+++ b/include/asm-generic/bitops/ops.h
@@ -85,7 +85,7 @@ static inline int __test_and_change_bit(int nr,
* @nr: bit number to test
* @addr: Address to start counting from
*/
-static inline int test_bit(int nr, const volatile unsigned long *addr)
+static inline bool test_bit(int nr, const volatile unsigned long *addr)
{
return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
}
diff --git a/scripts/include/asm-generic/bitops/atomic.h b/scripts/include/asm-generic/bitops/atomic.h
index 03fe804024df..8ed5fd6c7fd2 100644
--- a/scripts/include/asm-generic/bitops/atomic.h
+++ b/scripts/include/asm-generic/bitops/atomic.h
@@ -14,7 +14,7 @@ static inline void clear_bit(int nr, unsigned long *addr)
addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
}
-static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
+static __always_inline bool test_bit(unsigned int nr, const unsigned long *addr)
{
return ((1UL << (nr % BITS_PER_LONG)) &
(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
--
2.39.2
next reply other threads:[~2024-07-01 7:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 7:35 Ahmad Fatoum [this message]
2024-07-01 9:34 ` Sascha Hauer
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=20240701073509.176191-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.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