lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221028014834.572819-2-yury.norov@gmail.com>
Date:   Thu, 27 Oct 2022 18:48:29 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     linux-kernel@...r.kernel.org,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Yury Norov <yury.norov@...il.com>
Subject: [PATCH 1/6] bitmap: add bitmap_empty_from()

New function checks if a bitmap is empty starting from a specific bit.
In the following patch, it's used to replace _reg_op(REG_OP_ISFREE).

Signed-off-by: Yury Norov <yury.norov@...il.com>
---
 include/linux/bitmap.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 40e53a2ecc0d..f84553805c9c 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -49,6 +49,7 @@ struct device;
  *  bitmap_intersects(src1, src2, nbits)        Do *src1 and *src2 overlap?
  *  bitmap_subset(src1, src2, nbits)            Is *src1 a subset of *src2?
  *  bitmap_empty(src, nbits)                    Are all bits zero in *src?
+ *  bitmap_empty_from(src, start, nbits)        Are all bits zero in *src starting from @start?
  *  bitmap_full(src, nbits)                     Are all bits set in *src?
  *  bitmap_weight(src, nbits)                   Hamming Weight: number set bits
  *  bitmap_weight_and(src1, src2, nbits)        Hamming Weight of and'ed bitmap
@@ -433,6 +434,16 @@ static __always_inline bool bitmap_full(const unsigned long *src, unsigned int n
 	return find_first_zero_bit(src, nbits) == nbits;
 }
 
+static __always_inline
+bool bitmap_empty_from(const unsigned long *src, unsigned int start, unsigned int nbits)
+{
+	if (small_const_nbits_off(nbits, start))
+		return !(src[start/BITS_PER_LONG] &
+			 GENMASK((nbits - 1) % BITS_PER_LONG, start % BITS_PER_LONG));
+
+	return find_next_bit(src, nbits, start) == nbits;
+}
+
 static __always_inline
 unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits)
 {
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ