From 95d324fb1b48434f4c659e4c245c3bdeecdff22c Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Wed, 18 Mar 2026 20:43:48 -0400 Subject: bitmap: add test_zero_nbits() In most real-life cases, 0-length bitmap provided by user is a sign of an error. The API doesn't provide any guarantees on returned value, and the bitmap pointers are not dereferenced. Signed-off-by: Yury Norov --- lib/bitmap.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/bitmap.c') diff --git a/lib/bitmap.c b/lib/bitmap.c index 9dc526507875..1b897f94e0ff 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -69,6 +69,7 @@ bool __bitmap_or_equal(const unsigned long *bitmap1, tmp = (bitmap1[k] | bitmap2[k]) ^ bitmap3[k]; return (tmp & BITMAP_LAST_WORD_MASK(bits)) == 0; } +EXPORT_SYMBOL(__bitmap_or_equal); void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits) { @@ -360,6 +361,7 @@ unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitma { return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] | bitmap2[idx]; dst[idx]; }), bits); } +EXPORT_SYMBOL(__bitmap_weighted_or); void __bitmap_set(unsigned long *map, unsigned int start, int len) { -- cgit v1.2.3 From d57e74f10461b80c77d1678f646720f616fb8553 Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Sun, 1 Mar 2026 20:11:55 -0500 Subject: bitmap: introduce bitmap_weighted_xor() The function helps to XOR bitmaps and calculate Hamming weight of the result in one pass. Reviewed-by: Aleksandr Loktionov Reviewed-by: Jacob Keller Signed-off-by: Yury Norov --- lib/bitmap.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/bitmap.c') diff --git a/lib/bitmap.c b/lib/bitmap.c index 1b897f94e0ff..b9bfa157e095 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -363,6 +363,13 @@ unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitma } EXPORT_SYMBOL(__bitmap_weighted_or); +unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] ^ bitmap2[idx]; dst[idx]; }), bits); +} +EXPORT_SYMBOL(__bitmap_weighted_xor); + void __bitmap_set(unsigned long *map, unsigned int start, int len) { unsigned long *p = map + BIT_WORD(start); -- cgit v1.2.3