From bda80ef53f5b85917773ccebd3008f560658e342 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 6 Jun 2024 20:09:46 +1000 Subject: util: Use unsigned indices for bits in bitmaps A negative bit index in a bitmap doesn't make sense. Avoid this by construction by using unsigned indices. While we're there adjust bitmap_isset() to return a bool instead of an int. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index cc1c73b..5e854a2 100644 --- a/util.c +++ b/util.c @@ -232,7 +232,7 @@ int timespec_diff_ms(const struct timespec *a, const struct timespec *b) * @map: Pointer to bitmap * @bit: Bit number to set */ -void bitmap_set(uint8_t *map, int bit) +void bitmap_set(uint8_t *map, unsigned bit) { unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit); @@ -244,7 +244,7 @@ void bitmap_set(uint8_t *map, int bit) * @map: Pointer to bitmap * @bit: Bit number to clear */ -void bitmap_clear(uint8_t *map, int bit) +void bitmap_clear(uint8_t *map, unsigned bit) { unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit); @@ -256,9 +256,9 @@ void bitmap_clear(uint8_t *map, int bit) * @map: Pointer to bitmap * @bit: Bit number to check * - * Return: one if given bit is set, zero if it's not + * Return: true if given bit is set, false if it's not */ -int bitmap_isset(const uint8_t *map, int bit) +bool bitmap_isset(const uint8_t *map, unsigned bit) { const unsigned long *word = (const unsigned long *)map + BITMAP_WORD(bit); -- cgit v1.2.3