[PATCH master] bitops: change test_bit return type from int to bool
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Jul 1 00:35:09 PDT 2024
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 at 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
More information about the barebox
mailing list