From a3df88f06224066867bcb60f1616127c26fdabff Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 4 May 2023 21:41:15 +0100 Subject: [PATCH] kernel: fix bad offset calculation in bitmap_check() --- ds/bitmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ds/bitmap.c b/ds/bitmap.c index 01edc51..c1038f9 100644 --- a/ds/bitmap.c +++ b/ds/bitmap.c @@ -18,7 +18,7 @@ void bitmap_set(unsigned long *map, unsigned long bit) unsigned long index = bit / BITS_PER_WORD; unsigned long offset = (BITS_PER_WORD - bit - 1) & (BITS_PER_WORD - 1); unsigned long mask = 1ul << offset; - + map[index] |= mask; } @@ -27,18 +27,18 @@ void bitmap_clear(unsigned long *map, unsigned long bit) unsigned long index = bit / BITS_PER_WORD; unsigned long offset = bit & (BITS_PER_WORD - 1); unsigned long mask = 1ul << offset; - + map[index] &= ~mask; } bool bitmap_check(unsigned long *map, unsigned long bit) { unsigned long index = bit / BITS_PER_WORD; - unsigned long offset = bit & (BITS_PER_WORD - 1); + unsigned long offset = (BITS_PER_WORD - bit - 1) & (BITS_PER_WORD - 1); unsigned long mask = 1ul << offset; - + return (map[index] & mask) != 0 ? true : false; - + } unsigned int bitmap_count_set(unsigned long *map, unsigned long nbits)