From: kernel test robot <lkp@intel.com>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: oe-kbuild-all@lists.linux.dev
Subject: [koverstreet-bcachefs:bcachefs-testing 139/160] include/linux/random.h:104 get_random_u64_below() warn: always true condition '(ceil <= (~0)) => (0-u32max <= u32max)'
Date: Sun, 16 Mar 2025 22:23:16 +0800 [thread overview]
Message-ID: <202503162234.iyijTkoU-lkp@intel.com> (raw)
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
reply other threads:[~2025-03-16 14:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=202503162234.iyijTkoU-lkp@intel.com \
--to=lkp@intel.com \
--cc=kent.overstreet@linux.dev \
--cc=oe-kbuild-all@lists.linux.dev \
/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 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.