aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bitmap.c
diff options
context:
space:
mode:
authorWei Yang <[email protected]>2025-03-10 07:49:35 +0000
committerAndrew Morton <[email protected]>2025-03-17 19:17:00 +0000
commit82114e45131ff8006435ce40f4275c9c8910b404 (patch)
tree6963f1a74daee9f9a96538bd55b44e038caf47e7 /tools/lib/bitmap.c
parentlib/rbtree: add random seed (diff)
downloadkernel-82114e45131ff8006435ce40f4275c9c8910b404.tar.gz
kernel-82114e45131ff8006435ce40f4275c9c8910b404.zip
lib/interval_tree: add test case for interval_tree_iter_xxx() helpers
Verify interval_tree_iter_xxx() helpers could find intersection ranges as expected. [[email protected]: some of tools/ uses -Wno-unused-parameter] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Wei Yang <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: Jason Gunthorpe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
Diffstat (limited to 'tools/lib/bitmap.c')
-rw-r--r--tools/lib/bitmap.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
index 2178862bb114..51255c69754d 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -101,6 +101,26 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
return false;
}
+void __bitmap_set(unsigned long *map, unsigned int start, int len)
+{
+ unsigned long *p = map + BIT_WORD(start);
+ const unsigned int size = start + len;
+ int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
+ unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
+
+ while (len - bits_to_set >= 0) {
+ *p |= mask_to_set;
+ len -= bits_to_set;
+ bits_to_set = BITS_PER_LONG;
+ mask_to_set = ~0UL;
+ p++;
+ }
+ if (len) {
+ mask_to_set &= BITMAP_LAST_WORD_MASK(size);
+ *p |= mask_to_set;
+ }
+}
+
void __bitmap_clear(unsigned long *map, unsigned int start, int len)
{
unsigned long *p = map + BIT_WORD(start);