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]
Date:	Mon, 16 Feb 2009 14:58:40 +0200
From:	Benny Halevy <bhalevy@...asas.com>
To:	Rusty Russell <rusty@...tcorp.com.au>
Cc:	linux-kernel@...r.kernel.org, Benny Halevy <bhalevy@...asas.com>
Subject: [PATCH] bitmap: Cleanup find_last_bit

Fix cut & paste error in header comment.
Simplify implementation a bit.

Signed-off-by: Benny Halevy <bhalevy@...asas.com>
---

Rusty, we're using a similar mechanism for finding the highest slot ID
in use in the nfsv4.1 slot table and I'm going to moev it over to
using find_last_bit in our 2.6.29 patchset.
While going over your implementation I noticed a tiny cut & paste error in
bitops.h and I'd also like to propose a couple simplifications to make
the implementation a bit more readable (at least to me :).

Benny

 include/linux/bitops.h |    2 +-
 lib/find_last_bit.c    |   15 ++++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 6182913..886ebf0 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -142,7 +142,7 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr,
  * @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.
+ * Returns the bit number of the last set bit, or size.
  */
 extern unsigned long find_last_bit(const unsigned long *addr,
 				   unsigned long size);
diff --git a/lib/find_last_bit.c b/lib/find_last_bit.c
index 5d202e3..e9d9cdc 100644
--- a/lib/find_last_bit.c
+++ b/lib/find_last_bit.c
@@ -24,22 +24,23 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
 	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)))));
+	tmp = size & (BITS_PER_LONG-1);
+	if (tmp) {
+		tmp = addr[words] & (~0UL >> (BITS_PER_LONG - tmp));
 		if (tmp)
 			goto found;
 	}
 
 	while (words) {
 		tmp = addr[--words];
-		if (tmp) {
-found:
-			return words * BITS_PER_LONG + __fls(tmp);
-		}
+		if (tmp)
+			goto found;
 	}
 
 	/* Not found */
 	return size;
+
+found:
+	return words * BITS_PER_LONG + __fls(tmp);
 }
 EXPORT_SYMBOL(find_last_bit);
-- 
1.6.1.3

--
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