summaryrefslogtreecommitdiff
path: root/tools/lib/bitmap.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2024-08-13 13:52:30 -0700
committerAndrii Nakryiko <andrii@kernel.org>2024-08-13 13:52:30 -0700
commit50470d3899cdf06fd58def74dec87f31e13cda6f (patch)
tree9d4d04c0c394f079127752d6d5b796aa33b903ca /tools/lib/bitmap.c
parent4a4c013d3385b0db85dc361203dc42ff048b6fd6 (diff)
parentde12c3391bce10504c0e7bd767516c74110cfce1 (diff)
Merge remote-tracking branch 'vfs/stable-struct_fd'
Merge Al Viro's struct fd refactorings. Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
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 c3e4871967bc..2178862bb114 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -100,3 +100,23 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
return true;
return false;
}
+
+void __bitmap_clear(unsigned long *map, unsigned int start, int len)
+{
+ unsigned long *p = map + BIT_WORD(start);
+ const unsigned int size = start + len;
+ int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
+ unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
+
+ while (len - bits_to_clear >= 0) {
+ *p &= ~mask_to_clear;
+ len -= bits_to_clear;
+ bits_to_clear = BITS_PER_LONG;
+ mask_to_clear = ~0UL;
+ p++;
+ }
+ if (len) {
+ mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
+ *p &= ~mask_to_clear;
+ }
+}