[<prev] [next>] [day] [month] [year] [list]
Date: Mon, 10 Oct 2022 09:04:43 +0800
From: kernel test robot <lkp@...el.com>
To: "Jason A. Donenfeld" <zx2c4@...nel.org>
Cc: kbuild-all@...ts.01.org, zx2c4@...nel.org,
linux-kernel@...r.kernel.org
Subject: [crng-random:jd/get_random_u32_below 23/23]
include/linux/random.h:64:69: sparse: sparse: cast truncates bits from
constant value (30d41 becomes 41)
tree: git://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git jd/get_random_u32_below
head: 7e1db96a81c31621b3dfd6247d6e6dbad2af6893
commit: 7e1db96a81c31621b3dfd6247d6e6dbad2af6893 [23/23] random: use rejection sampling for uniform bounded integers
config: i386-randconfig-s003
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git/commit/?id=7e1db96a81c31621b3dfd6247d6e6dbad2af6893
git remote add crng-random git://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git
git fetch --no-tags crng-random jd/get_random_u32_below
git checkout 7e1db96a81c31621b3dfd6247d6e6dbad2af6893
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash net/ipv6/ net/netlink/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>
sparse warnings: (new ones prefixed by >>)
net/ipv6/addrconf.c: note: in included file (through include/linux/nodemask.h, include/linux/sched.h, include/linux/sched/signal.h):
>> include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (30d41 becomes 41)
>> include/linux/random.h:68:71: sparse: sparse: cast truncates bits from constant value (30d41 becomes d41)
>> include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (30d41 becomes 41)
>> include/linux/random.h:68:71: sparse: sparse: cast truncates bits from constant value (30d41 becomes d41)
>> include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (30d41 becomes 41)
>> include/linux/random.h:68:71: sparse: sparse: cast truncates bits from constant value (30d41 becomes d41)
>> include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (30d41 becomes 41)
>> include/linux/random.h:68:71: sparse: sparse: cast truncates bits from constant value (30d41 becomes d41)
--
net/netlink/af_netlink.c: note: in included file (through include/linux/nodemask.h, include/linux/mmzone.h, include/linux/gfp.h, ...):
>> include/linux/random.h:64:69: sparse: sparse: cast truncates bits from constant value (7ffff000 becomes 0)
>> include/linux/random.h:68:71: sparse: sparse: cast truncates bits from constant value (7ffff000 becomes f000)
net/netlink/af_netlink.c:2568:13: sparse: sparse: context imbalance in 'netlink_walk_start' - wrong count at exit
net/netlink/af_netlink.c:2574:13: sparse: sparse: context imbalance in 'netlink_walk_stop' - unexpected unlock
net/netlink/af_netlink.c:2624:9: sparse: sparse: context imbalance in 'netlink_seq_start' - wrong count at exit
vim +64 include/linux/random.h
53
54 u32 __get_random_u32_below(u32 ceil);
55 /* Returns a random integer in the interval [0, ceil), with uniform distribution. */
56 static inline u32 get_random_u32_below(u32 ceil)
57 {
58 if (!__builtin_constant_p(ceil))
59 return __get_random_u32_below(ceil);
60
61 for (;;) {
62 if (ceil <= 1U << 8) {
63 u32 mult = ceil * get_random_u8();
> 64 if (is_power_of_2(ceil) || (u8)mult >= -(u8)ceil % ceil)
65 return mult >> 8;
66 } else if (ceil <= 1U << 16) {
67 u32 mult = ceil * get_random_u16();
> 68 if (is_power_of_2(ceil) || (u16)mult >= -(u16)ceil % ceil)
69 return mult >> 16;
70 } else {
71 u64 mult = (u64)ceil * get_random_u32();
72 if (is_power_of_2(ceil) || (u32)mult >= -ceil % ceil)
73 return mult >> 32;
74 }
75 }
76 }
77
--
0-DAY CI Kernel Test Service
https://01.org/lkp
View attachment "config" of type "text/plain" (158558 bytes)
Powered by blists - more mailing lists