[norov:bitmap_param 26/26] lib/find_bit.c:309 find_random_bit() warn: always true condition '(w <= (~0)) => (0-u32max <= u32max)'

kernel test robot <[email protected]> Fri, 24 Jul 2026 01:20:39 +0800
Newsgroups dev.linux.lists.oe-kbuild-all
Message-ID <[email protected]>
tree:   https://github.com/norov/linux bitmap_param
head:   7973e783d2679c9ea1219c4beca33564fea1b38d
commit: 7973e783d2679c9ea1219c4beca33564fea1b38d [26/26] bitmap: return unsigned long from weight operations
config: i386-randconfig-141 (https://download.01.org/0day-ci/archive/20260724/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
smatch: v0.5.0-9187-g5189e3fb

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

smatch warnings:
lib/find_bit.c:309 find_random_bit() warn: always true condition '(w <= (~0)) => (0-u32max <= u32max)'

vim +309 lib/find_bit.c

   288	
   289	/**
   290	 * find_random_bit - find a set bit at random position
   291	 * @addr: The address to base the search on
   292	 * @size: The bitmap size in bits
   293	 *
   294	 * Returns: a position of a random set bit; >= @size otherwise
   295	 */
   296	unsigned long find_random_bit(const unsigned long *addr, unsigned long size)
   297	{
   298		unsigned long w = bitmap_weight(addr, size);
   299	
   300		switch (w) {
   301		case 0:
   302			return size;
   303		case 1:
   304			/* Performance trick for single-bit bitmaps */
   305			return find_first_bit(addr, size);
   306		default: {
   307			unsigned long n, random;
   308	
 > 309			if (w <= U32_MAX) {

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki