kernel: fix bad offset calculation in bitmap_check()

This commit is contained in:
2023-05-04 21:41:15 +01:00
parent 5611fce641
commit a3df88f062

View File

@@ -18,7 +18,7 @@ void bitmap_set(unsigned long *map, unsigned long bit)
unsigned long index = bit / BITS_PER_WORD; unsigned long index = bit / BITS_PER_WORD;
unsigned long offset = (BITS_PER_WORD - bit - 1) & (BITS_PER_WORD - 1); unsigned long offset = (BITS_PER_WORD - bit - 1) & (BITS_PER_WORD - 1);
unsigned long mask = 1ul << offset; unsigned long mask = 1ul << offset;
map[index] |= mask; 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 index = bit / BITS_PER_WORD;
unsigned long offset = bit & (BITS_PER_WORD - 1); unsigned long offset = bit & (BITS_PER_WORD - 1);
unsigned long mask = 1ul << offset; unsigned long mask = 1ul << offset;
map[index] &= ~mask; map[index] &= ~mask;
} }
bool bitmap_check(unsigned long *map, unsigned long bit) bool bitmap_check(unsigned long *map, unsigned long bit)
{ {
unsigned long index = bit / BITS_PER_WORD; 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; unsigned long mask = 1ul << offset;
return (map[index] & mask) != 0 ? true : false; return (map[index] & mask) != 0 ? true : false;
} }
unsigned int bitmap_count_set(unsigned long *map, unsigned long nbits) unsigned int bitmap_count_set(unsigned long *map, unsigned long nbits)