From patchwork Fri Jan 13 15:53:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/7] bitops: introduce list_for_each_clear_bit From: Akinobu Mita X-Patchwork-Id: 135912 Message-Id: <1326470004-10096-4-git-send-email-akinobu.mita@gmail.com> To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Cc: linux-s390@vger.kernel.org, linux-usb@vger.kernel.org, Robert Richter , x86@kernel.org, Heiko Carstens , Akinobu Mita , Ingo Molnar , linux-mtd@lists.infradead.org, "H. Peter Anvin" , Martin Schwidefsky , linux390@de.ibm.com, Thomas Gleixner , David Woodhouse Date: Sat, 14 Jan 2012 00:53:20 +0900 Introduce list_for_each_clear_bit() and list_for_each_clear_bit_from(). They are similar to for_each_set_bit() and list_for_each_set_bit_from(), but they iterate over all the cleared bits in a memory region. Signed-off-by: Akinobu Mita Cc: Robert Richter Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux390@de.ibm.com Cc: linux-s390@vger.kernel.org Cc: linux-usb@vger.kernel.org --- include/linux/bitops.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 15ad702..c8a0d65 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -32,6 +32,17 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1)) +#define for_each_clear_bit(bit, addr, size) \ + for ((bit) = find_first_zero_bit((addr), (size)); \ + (bit) < (size); \ + (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) + +/* same as for_each_clear_bit() but use bit as value to start with */ +#define for_each_clear_bit_from(bit, addr, size) \ + for ((bit) = find_next_zero_bit((addr), (size), (bit)); \ + (bit) < (size); \ + (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) + static __inline__ int get_bitmask_order(unsigned int count) { int order;