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>] [day] [month] [year] [list]
Message-ID: <20201206064711.GA5941@ubuntu>
Date:   Sun, 6 Dec 2020 15:47:11 +0900
From:   Levi Yun <ppbuk5246@...il.com>
To:     akpm@...ux-foundation.org, yury.norov@...il.com,
        andriy.shevchenko@...ux.intel.com,
        richard.weiyang@...ux.alibaba.com, christian.brauner@...ntu.com,
        arnd@...db.de, jpoimboe@...hat.com, changbin.du@...el.com,
        rdunlap@...radead.org, masahiroy@...nel.org,
        gregkh@...uxfoundation.org, peterz@...radead.org,
        peter.enderborg@...y.com, krzk@...nel.org,
        brendanhiggins@...gle.com, keescook@...omium.org,
        broonie@...nel.org, matti.vaittinen@...rohmeurope.com,
        mhiramat@...nel.org, jpa@....mail.kapsi.fi, nivedita@...m.mit.edu,
        glider@...gle.com, orson.zhai@...soc.com,
        takahiro.akashi@...aro.org, clm@...com, josef@...icpanda.com,
        dsterba@...e.com, dushistov@...l.ru
Cc:     linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org,
        linux-btrfs@...r.kernel.org
Subject: [PATCH v2 2/8] linux/bitops.h: Add find_each_*_bit_reverse macros

Add reverse routine for find_each_*_bit using find_last_bit and
find_last_zero_bit.
for correspondant usage wtih find_each_*_bit macros we use same
parameters,
But when we use these macro different from find_each_*_bit,
@size should be a variable NOT constants.

Signed-off-by: Levi Yun <ppbuk5246@...il.com>
---
 include/linux/bitops.h | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 5b74bdf159d6..f6ab611ca732 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -50,6 +50,31 @@ extern unsigned long __sw_hweight64(__u64 w);
 	     (bit) < (size);					\
 	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
 
+/**
+ * find_each_*_reverse's @size should be variable NOT constant.
+ */
+#define for_each_set_bit_reverse(bit, addr, size) \
+	for ((bit) = find_last_bit((addr), (size));		\
+	     (bit) < (size) && (size);					\
+	     (size) = (bit), (bit) = find_last_bit((addr), (size)))
+
+/* same as for_each_set_bit_reverse() but use bit as value to start with */
+#define for_each_set_bit_from_reverse(bit, addr, size) \
+	for ((size) = (bit + 1), (bit) = find_last_bit((addr), (size));	\
+	     (bit) < (size) && (size);					\
+	     (size) = (bit), (bit) = find_last_bit((addr), (size)))
+
+#define for_each_clear_bit_reverse(bit, addr, size) \
+	for ((bit) = find_last_zero_bit((addr), (size));	\
+	     (bit) < (size) && (size);					\
+	     (size) = (bit), (bit) = find_last_zero_bit((addr), (size)))
+
+/* same as for_each_clear_bit_reverse() but use bit as value to start with */
+#define for_each_clear_bit_from_reverse(bit, addr, size) \
+	for ((size) = (bit + 1), (bit) = find_last_zero_bit((addr), (size));	\
+	     (bit) < (size) && (size);					\
+	     (size) = (bit), (bit) = find_last_zero_bit((addr), (size)))
+
 /**
  * for_each_set_clump8 - iterate over bitmap for each 8-bit clump with set bits
  * @start: bit offset to start search and to store the current iteration offset
@@ -283,17 +308,5 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
 })
 #endif
 
-#ifndef find_last_bit
-/**
- * find_last_bit - find the last set bit in a memory region
- * @addr: The address to start the search at
- * @size: The number of bits to search
- *
- * Returns the bit number of the last set bit, or size.
- */
-extern unsigned long find_last_bit(const unsigned long *addr,
-				   unsigned long size);
-#endif
-
 #endif /* __KERNEL__ */
 #endif
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ