From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752469AbbC2CEP (ORCPT ); Sat, 28 Mar 2015 22:04:15 -0400 Received: from mail-lb0-f179.google.com ([209.85.217.179]:35607 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbbC2CEO (ORCPT ); Sat, 28 Mar 2015 22:04:14 -0400 From: Yury Norov To: linux@horizon.com, klimov.linux@gmail.com, linux@rasmusvillemoes.dk, akpm@linux-foundation.org Cc: yury.norov@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] lib: bitmap_[empty,full]: remove code duplication Date: Sun, 29 Mar 2015 05:03:55 +0300 Message-Id: <1427594635-11759-1-git-send-email-yury.norov@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426528599-3735-1-git-send-email-yury.norov@gmail.com> References: <1426528599-3735-1-git-send-email-yury.norov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function 'bitmap_empty' has it's own implementation. But it's clearly as simple as: "find_first_bit(src, nbits) == nbits" The same is true for 'bitmap_full'. --- include/linux/bitmap.h | 8 ++++---- lib/bitmap.c | 30 ------------------------------ 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index be4fa5d..ea17cca 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -283,16 +283,16 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits) { if (small_const_nbits(nbits)) return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); - else - return __bitmap_empty(src, nbits); + + return find_first_bit(src, nbits) == nbits; } static inline int bitmap_full(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); - else - return __bitmap_full(src, nbits); + + return find_first_zero_bit(src, nbits) == nbits; } static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) diff --git a/lib/bitmap.c b/lib/bitmap.c index d456f4c1..64c0926 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -42,36 +42,6 @@ * for the best explanations of this ordering. */ -int __bitmap_empty(const unsigned long *bitmap, unsigned int bits) -{ - unsigned int k, lim = bits/BITS_PER_LONG; - for (k = 0; k < lim; ++k) - if (bitmap[k]) - return 0; - - if (bits % BITS_PER_LONG) - if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) - return 0; - - return 1; -} -EXPORT_SYMBOL(__bitmap_empty); - -int __bitmap_full(const unsigned long *bitmap, unsigned int bits) -{ - unsigned int k, lim = bits/BITS_PER_LONG; - for (k = 0; k < lim; ++k) - if (~bitmap[k]) - return 0; - - if (bits % BITS_PER_LONG) - if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) - return 0; - - return 1; -} -EXPORT_SYMBOL(__bitmap_full); - int __bitmap_equal(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits) { -- 2.1.0