All of lore.kernel.org
 help / color / mirror / Atom feed
* [koverstreet-bcachefs:bcachefs-testing 139/160] include/linux/random.h:104 get_random_u64_below() warn: always true condition '(ceil <= (~0)) => (0-u32max <= u32max)'
@ 2025-03-16 14:23 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2025-03-16 14:23 UTC (permalink / raw)
  To: Kent Overstreet; +Cc: oe-kbuild-all

tree:   https://github.com/koverstreet/bcachefs bcachefs-testing
head:   6d7f54c162635934218ea0cede09f68e40e3bc2f
commit: 3ebf48025118a2db43fab6b283ceda9bd7998937 [139/160] bcachefs: kill bch2_get_random_u64_below()
config: i386-randconfig-141-20250316 (https://download.01.org/0day-ci/archive/20250316/202503162234.iyijTkoU-lkp@intel.com/config)
compiler: clang version 20.1.0 (https://github.com/llvm/llvm-project 24a30daaa559829ad079f2ff7f73eb4e18095f88)

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/202503162234.iyijTkoU-lkp@intel.com/

smatch warnings:
include/linux/random.h:104 get_random_u64_below() warn: always true condition '(ceil <= (~0)) => (0-u32max <= u32max)'

vim +104 include/linux/random.h

a83003c2e557d2a Kent Overstreet 2025-03-13   95  
a83003c2e557d2a Kent Overstreet 2025-03-13   96  static inline u64 get_random_u64_below(u32 ceil)
a83003c2e557d2a Kent Overstreet 2025-03-13   97  {
a83003c2e557d2a Kent Overstreet 2025-03-13   98  	if (!__builtin_constant_p(ceil))
a83003c2e557d2a Kent Overstreet 2025-03-13   99  		return __get_random_u64_below(ceil);
a83003c2e557d2a Kent Overstreet 2025-03-13  100  
a83003c2e557d2a Kent Overstreet 2025-03-13  101  	BUILD_BUG_ON_MSG(!ceil, "get_random_u64_below() must take ceil > 0");
a83003c2e557d2a Kent Overstreet 2025-03-13  102  	if (ceil <= 1)
a83003c2e557d2a Kent Overstreet 2025-03-13  103  		return 0;
a83003c2e557d2a Kent Overstreet 2025-03-13 @104  	if (ceil <= U32_MAX)
a83003c2e557d2a Kent Overstreet 2025-03-13  105  		return get_random_u32_below(ceil);
a83003c2e557d2a Kent Overstreet 2025-03-13  106  
a83003c2e557d2a Kent Overstreet 2025-03-13  107  	for (;;) {
a83003c2e557d2a Kent Overstreet 2025-03-13  108  		u64 rand = get_random_u64();
a83003c2e557d2a Kent Overstreet 2025-03-13  109  		u64 mult = ceil * rand;
a83003c2e557d2a Kent Overstreet 2025-03-13  110  		if (likely(mult >= -ceil % ceil))
a83003c2e557d2a Kent Overstreet 2025-03-13  111  			return mul_u64_u64_shr(ceil, rand, 64);
a83003c2e557d2a Kent Overstreet 2025-03-13  112  	}
a83003c2e557d2a Kent Overstreet 2025-03-13  113  }
a83003c2e557d2a Kent Overstreet 2025-03-13  114  

:::::: The code at line 104 was first introduced by commit
:::::: a83003c2e557d2aa65561df407a61cb44900d481 random: get_random_u64_below()

:::::: TO: Kent Overstreet <kent.overstreet@linux.dev>
:::::: CC: Kent Overstreet <kent.overstreet@linux.dev>

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-16 14:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-16 14:23 [koverstreet-bcachefs:bcachefs-testing 139/160] include/linux/random.h:104 get_random_u64_below() warn: always true condition '(ceil <= (~0)) => (0-u32max <= u32max)' kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.