From: Yury Norov <ynorov@nvidia.com>
To: linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 2/3] bitmap: exclude nbits == 0 cases from bitmap test
Date: Wed, 18 Mar 2026 20:43:47 -0400 [thread overview]
Message-ID: <20260319004349.849281-3-ynorov@nvidia.com> (raw)
In-Reply-To: <20260319004349.849281-1-ynorov@nvidia.com>
Bitmap API handles nbits == 0 in most cases correctly, i.e. it doesn't
dereferene underlying bitmap and returns a sane value where convenient,
or implementation defined, or undef.
Implicitly testing nbits == 0 case, however, may make an impression that
this is a regular case. This is wrong. In most cases nbits == 0 is a
sign of an error on a client side. The tests should not make such an
implression.
This patch reworks the existing tests to not test nbits == 0. The
following patch adds an explicit test for it with an appropriate
precaution.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
lib/test_bitmap.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index eeb497016ed3..b6f27c632c75 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -653,7 +653,7 @@ static void __init test_bitmap_arr32(void)
memset(arr, 0xa5, sizeof(arr));
- for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
+ for (nbits = 1; nbits < EXP1_IN_BITS; ++nbits) {
bitmap_to_arr32(arr, exp1, nbits);
bitmap_from_arr32(bmap2, arr, nbits);
expect_eq_bitmap(bmap2, exp1, nbits);
@@ -681,7 +681,7 @@ static void __init test_bitmap_arr64(void)
memset(arr, 0xa5, sizeof(arr));
- for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
+ for (nbits = 1; nbits < EXP1_IN_BITS; ++nbits) {
memset(bmap2, 0xff, sizeof(arr));
bitmap_to_arr64(arr, exp1, nbits);
bitmap_from_arr64(bmap2, arr, nbits);
@@ -714,7 +714,7 @@ static void noinline __init test_mem_optimisations(void)
unsigned int start, nbits;
for (start = 0; start < 1024; start += 8) {
- for (nbits = 0; nbits < 1024 - start; nbits += 8) {
+ for (nbits = 1; nbits < 1024 - start; nbits += 8) {
memset(bmap1, 0x5a, sizeof(bmap1));
memset(bmap2, 0x5a, sizeof(bmap2));
@@ -873,7 +873,7 @@ static void __init test_bitmap_weight(void)
/* Test outline implementation */
w = bitmap_weight(exp1, EXP1_IN_BITS);
- for (bit = 0; bit < EXP1_IN_BITS; bit++) {
+ for (bit = 1; bit < EXP1_IN_BITS; bit++) {
w1 = bitmap_weight(exp1, bit);
w2 = bitmap_weight_from(exp1, bit, EXP1_IN_BITS);
expect_eq_uint(w1 + w2, w);
--
2.43.0
next prev parent reply other threads:[~2026-03-19 0:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 0:43 [PATCH 0/3] bitmap: add new tests Yury Norov
2026-03-19 0:43 ` [PATCH 1/3] bitmap: test bitmap_weight() for more Yury Norov
2026-03-19 0:43 ` Yury Norov [this message]
2026-03-19 0:43 ` [PATCH 3/3] bitmap: add test_zero_nbits() Yury Norov
2026-03-21 17:09 ` kernel test robot
2026-03-23 17:56 ` Yury Norov
2026-03-24 0:52 ` Philip Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260319004349.849281-3-ynorov@nvidia.com \
--to=ynorov@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox