[PATCH 3/3] bitmap: add test_zero_nbits()

Yury Norov posted 3 patches 2 weeks, 4 days ago
[PATCH 3/3] bitmap: add test_zero_nbits()
Posted by Yury Norov 2 weeks, 4 days ago
In most real-life cases, 0-length bitmap provided by user is a sign of
an error. The API doesn't provide any guarantees on returned value, and
the bitmap pointers are not dereferenced.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
 lib/test_bitmap.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index b6f27c632c75..7a61ea858837 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -1467,6 +1467,62 @@ static void __init test_bitmap_write_perf(void)
 	pr_info("%s:\t\t%llu\n", __func__, time);
 }
 
+/*
+ * nbits == 0 is most commonly not a valid case. Bitmap users should revisit
+ * the caller logic. Bitmap API doesn't provide any guarantees on returned
+ * value. The pointers are not dereferenced. The return value is intentionally
+ * ignored.
+ */
+static void __init test_zero_nbits(void)
+{
+	static volatile __always_used unsigned long ret __initdata;
+
+	bitmap_clear(NULL, 0, 0);
+	bitmap_complement(NULL, NULL, 0);
+	bitmap_copy(NULL, NULL, 0);
+	bitmap_copy_clear_tail(NULL, NULL, 0);
+	bitmap_fill(NULL, 0);
+	bitmap_from_arr32(NULL, NULL, 0);
+	bitmap_from_arr64(NULL, NULL, 0);
+	bitmap_or(NULL, NULL, NULL, 0);
+	bitmap_set(NULL, 0, 0);
+	bitmap_shift_left(NULL, NULL, 0, 0);
+	bitmap_shift_right(NULL, NULL, 0, 0);
+	bitmap_to_arr32(NULL, NULL, 0);
+	bitmap_to_arr64(NULL, NULL, 0);
+	bitmap_write(NULL, 0, 0, 0);
+	bitmap_xor(NULL, NULL, NULL, 0);
+	bitmap_zero(NULL, 0);
+
+	ret = bitmap_and(NULL, NULL, NULL, 0);
+	ret = bitmap_empty(NULL, 0);
+	ret = bitmap_equal(NULL, NULL, 0);
+	ret = bitmap_full(NULL, 0);
+	ret = bitmap_or_equal(NULL, NULL, NULL, 0);
+	ret = bitmap_read(NULL, 0, 0);
+	ret = bitmap_subset(NULL, NULL, 0);
+	ret = bitmap_weight(NULL, 0);
+	ret = bitmap_weight_and(NULL, NULL, 0);
+	ret = bitmap_weight_andnot(NULL, NULL, 0);
+	ret = bitmap_weight_from(NULL, 0, 0);
+	ret = bitmap_weighted_or(NULL, NULL, NULL, 0);
+
+	ret = find_first_and_and_bit(NULL, NULL, NULL, 0);
+	ret = find_first_and_bit(NULL, NULL, 0);
+	ret = find_first_andnot_bit(NULL, NULL, 0);
+	ret = find_first_bit(NULL, 0);
+	ret = find_first_zero_bit(NULL, 0);
+	ret = find_last_bit(NULL, 0);
+	ret = find_next_and_bit(NULL, NULL, 0, 0);
+	ret = find_next_andnot_bit(NULL, NULL, 0, 0);
+	ret = find_next_bit(NULL, 0, 0);
+	ret = find_next_clump8(NULL, NULL, 0, 0);
+	ret = find_next_zero_bit(NULL, 0, 0);
+	ret = find_nth_and_bit(NULL, NULL, 0, 0);
+	ret = find_nth_bit(NULL, 0, 0);
+	ret = find_random_bit(NULL, 0);
+}
+
 #undef TEST_BIT_LEN
 
 static void __init selftest(void)
@@ -1490,6 +1546,7 @@ static void __init selftest(void)
 	test_bitmap_read_perf();
 	test_bitmap_weight();
 	test_bitmap_write_perf();
+	test_zero_nbits();
 
 	test_find_nth_bit();
 	test_for_each_set_bit();
-- 
2.43.0
Re: [PATCH 3/3] bitmap: add test_zero_nbits()
Posted by kernel test robot 2 weeks, 1 day ago
Hi Yury,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20260318]
[cannot apply to akpm-mm/mm-nonmm-unstable v7.0-rc4 v7.0-rc3 v7.0-rc2 linus/master v7.0-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/bitmap-test-bitmap_weight-for-more/20260319-221930
base:   next-20260318
patch link:    https://lore.kernel.org/r/20260319004349.849281-4-ynorov%40nvidia.com
patch subject: [PATCH 3/3] bitmap: add test_zero_nbits()
config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603220114.k5BHBav5-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__bitmap_or_equal" [lib/test_bitmap.ko] undefined!
ERROR: modpost: "__bitmap_weighted_or" [lib/test_bitmap.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 3/3] bitmap: add test_zero_nbits()
Posted by Yury Norov 1 week, 6 days ago
On Sun, Mar 22, 2026 at 01:09:51AM +0800, kernel test robot wrote:
> Hi Yury,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on next-20260318]
> [cannot apply to akpm-mm/mm-nonmm-unstable v7.0-rc4 v7.0-rc3 v7.0-rc2 linus/master v7.0-rc4]

Just as said in cover-letter: apply it on top of -next, or
bitmap-for-next.

Applying this in bitmap-for-next for testing.

Thanks,
Yury

> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/bitmap-test-bitmap_weight-for-more/20260319-221930
> base:   next-20260318
> patch link:    https://lore.kernel.org/r/20260319004349.849281-4-ynorov%40nvidia.com
> patch subject: [PATCH 3/3] bitmap: add test_zero_nbits()
> config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/config)
> compiler: nios2-linux-gcc (GCC) 11.5.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202603220114.k5BHBav5-lkp@intel.com/
> 
> All errors (new ones prefixed by >>, old ones prefixed by <<):
> 
> >> ERROR: modpost: "__bitmap_or_equal" [lib/test_bitmap.ko] undefined!
> ERROR: modpost: "__bitmap_weighted_or" [lib/test_bitmap.ko] undefined!
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
Re: [PATCH 3/3] bitmap: add test_zero_nbits()
Posted by Philip Li 1 week, 6 days ago
On Mon, Mar 23, 2026 at 01:56:01PM -0400, Yury Norov wrote:
> On Sun, Mar 22, 2026 at 01:09:51AM +0800, kernel test robot wrote:
> > Hi Yury,
> > 
> > kernel test robot noticed the following build errors:
> > 
> > [auto build test ERROR on next-20260318]
> > [cannot apply to akpm-mm/mm-nonmm-unstable v7.0-rc4 v7.0-rc3 v7.0-rc2 linus/master v7.0-rc4]
> 
> Just as said in cover-letter: apply it on top of -next, or
> bitmap-for-next.

Got it, sorry for the false report. The report is based on next-20260318, which should use
next-20260319 as latest base.

> 
> Applying this in bitmap-for-next for testing.
> 
> Thanks,
> Yury
> 
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> > 
> > url:    https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/bitmap-test-bitmap_weight-for-more/20260319-221930
> > base:   next-20260318
> > patch link:    https://lore.kernel.org/r/20260319004349.849281-4-ynorov%40nvidia.com
> > patch subject: [PATCH 3/3] bitmap: add test_zero_nbits()
> > config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/config)
> > compiler: nios2-linux-gcc (GCC) 11.5.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/202603220114.k5BHBav5-lkp@intel.com/reproduce)
> > 
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202603220114.k5BHBav5-lkp@intel.com/
> > 
> > All errors (new ones prefixed by >>, old ones prefixed by <<):
> > 
> > >> ERROR: modpost: "__bitmap_or_equal" [lib/test_bitmap.ko] undefined!
> > ERROR: modpost: "__bitmap_weighted_or" [lib/test_bitmap.ko] undefined!
> > 
> > -- 
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
>