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-next>] [day] [month] [year] [list]
Date:	Mon, 1 Dec 2008 18:48:31 +1030
From:	Rusty Russell <rusty@...tcorp.com.au>
To:	linux-kernel@...r.kernel.org
Cc:	Ingo Molnar <mingo@...hat.com>, Mike Travis <travis@....com>
Subject: [PATCH 5/6] bitmap: find_last_bit()

Impact: New API

As the name suggests.  For the moment everyone uses the generic one.

Signed-off-by: Rusty Russell <rusty@...tcorp.com.au>
---
 include/linux/bitops.h |   13 ++++++++++++-
 lib/Kconfig            |    4 ++++
 lib/Makefile           |    1 +
 lib/find_next_bit.c    |   31 +++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)

diff -r 22df8a8dec81 include/linux/bitops.h
--- a/include/linux/bitops.h	Sat Oct 18 04:46:13 2008 +1100
+++ b/include/linux/bitops.h	Tue Oct 21 17:06:35 2008 +1100
@@ -134,8 +134,19 @@ extern unsigned long find_first_bit(cons
  */
 extern unsigned long find_first_zero_bit(const unsigned long *addr,
 					 unsigned long size);
+#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
 
-#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
+#ifdef CONFIG_GENERIC_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 maximum size to search
+ *
+ * Returns the bit number of the first set bit, or size.
+ */
+extern unsigned long find_last_bit(const unsigned long *addr,
+				   unsigned long size);
+#endif /* CONFIG_GENERIC_FIND_LAST_BIT */
 
 #ifdef CONFIG_GENERIC_FIND_NEXT_BIT
 
diff -r 22df8a8dec81 lib/Kconfig
--- a/lib/Kconfig	Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/Kconfig	Tue Oct 21 17:06:35 2008 +1100
@@ -12,6 +12,10 @@ config GENERIC_FIND_FIRST_BIT
 
 config GENERIC_FIND_NEXT_BIT
 	bool
+
+config GENERIC_FIND_LAST_BIT
+	bool
+	default y
 
 config CRC_CCITT
 	tristate "CRC-CCITT functions"
diff -r 22df8a8dec81 lib/Makefile
--- a/lib/Makefile	Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/Makefile	Tue Oct 21 17:06:35 2008 +1100
@@ -37,6 +37,7 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) +=
 lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
 lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
 lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
+lib-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_next_bit.o
 obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
 obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
 obj-$(CONFIG_PLIST) += plist.o
diff -r 22df8a8dec81 lib/find_next_bit.c
--- a/lib/find_next_bit.c	Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/find_next_bit.c	Tue Oct 21 17:06:35 2008 +1100
@@ -159,6 +159,37 @@ EXPORT_SYMBOL(find_first_zero_bit);
 EXPORT_SYMBOL(find_first_zero_bit);
 #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
 
+#ifdef CONFIG_GENERIC_FIND_LAST_BIT
+unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
+{
+	unsigned long words;
+	unsigned long tmp;
+
+	/* Start at final word. */
+	words = size / BITS_PER_LONG;
+
+	/* Partial final word? */
+	if (size & (BITS_PER_LONG-1)) {
+		tmp = (addr[words] & (~0UL >> (BITS_PER_LONG
+					 - (size & (BITS_PER_LONG-1)))));
+		if (tmp)
+			goto found;
+	}
+
+	while (words) {
+		tmp = addr[--words];
+		if (tmp) {
+found:
+			return words * BITS_PER_LONG + __fls(tmp);
+		}
+	}
+
+	/* Not found */
+	return size;
+}
+EXPORT_SYMBOL(find_last_bit);
+#endif /* CONFIG_GENERIC_FIND_LAST_BIT */
+
 #ifdef __BIG_ENDIAN
 
 /* include/linux/byteorder does not support "unsigned long" type */


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ