mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] bitops: change test_bit return type from int to bool
@ 2024-07-01  7:35 Ahmad Fatoum
  2024-07-01  9:34 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-01  7:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




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

* Re: [PATCH master] bitops: change test_bit return type from int to bool
  2024-07-01  7:35 [PATCH master] bitops: change test_bit return type from int to bool Ahmad Fatoum
@ 2024-07-01  9:34 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-07-01  9:34 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 01 Jul 2024 09:35:09 +0200, Ahmad Fatoum wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] bitops: change test_bit return type from int to bool
      https://git.pengutronix.de/cgit/barebox/commit/?id=4e47b8b03bce (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-07-01  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01  7:35 [PATCH master] bitops: change test_bit return type from int to bool Ahmad Fatoum
2024-07-01  9:34 ` Sascha Hauer

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