Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760117AbeAIRYk (ORCPT + 1 other); Tue, 9 Jan 2018 12:24:40 -0500 Received: from mga11.intel.com ([192.55.52.93]:35340 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760100AbeAIRYe (ORCPT ); Tue, 9 Jan 2018 12:24:34 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,336,1511856000"; d="scan'208";a="17905364" From: Andy Shevchenko To: Andrew Morton , linux-kernel@vger.kernel.org, Rasmus Villemoes , Randy Dunlap , Yury Norov Cc: Andy Shevchenko Subject: [PATCH v1 4/4] bitmap: Make bitmap_fill() and bitmap_zero() consistent Date: Tue, 9 Jan 2018 19:24:30 +0200 Message-Id: <20180109172430.87452-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180109172430.87452-1-andriy.shevchenko@linux.intel.com> References: <20180109172430.87452-1-andriy.shevchenko@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Behaviour of bitmap_fill() differs from bitmap_zero() in a way how bits behind bitmap are handed. bitmap_zero() clears entire bitmap by unsigned long boundary, while bitmap_fill() mimics bitmap_set(). Here we change bitmap_fill() behaviour to be consistent with bitmap_zero() and add a note to documentation. The change might reveal some bugs in the code where unused bits handled differently and in such cases bitmap_set() has to be used. Suggested-by: Rasmus Villemoes Signed-off-by: Andy Shevchenko --- include/linux/bitmap.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index a17b5121d4f5..49aea0b37994 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -67,6 +67,11 @@ * bitmap_from_arr32(dst, buf, nbits) Copy nbits from u32[] buf to dst * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst * + * Note, bitmap_zero() and bitmap_fill() operate over the region of + * unsigned longs, that is, bits behind bitmap till the unsigned long + * boundary will be zeroed or filled as well. Consider to use + * bitmap_clear() or bitmap_set() to make explicit zeroing or filling + * respectively. */ /** @@ -206,12 +211,12 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) { - unsigned int nlongs = BITS_TO_LONGS(nbits); - if (!small_const_nbits(nbits)) { - unsigned int len = (nlongs - 1) * sizeof(unsigned long); - memset(dst, 0xff, len); + if (small_const_nbits(nbits)) + *dst = ~0UL; + else { + unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memset(dst, 0xff, len); } - dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); } static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, -- 2.15.1