* lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64')
@ 2023-02-08 4:56 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-02-08 4:56 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp
::::::
:::::: Manual check reason: "low confidence bisect report"
:::::: Manual check reason: "low confidence static check first_new_problem: lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: "Seung-Woo Kim" <sw0312.kim@samsung.com>
CC: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
CC: Florian Fainelli <f.fainelli@gmail.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 0983f6bf2bfc0789b51ddf7315f644ff4da50acb
commit: d539fee9f825b0c8eac049732c83562b28a483b5 ARM: 9253/1: ubsan: select ARCH_HAS_UBSAN_SANITIZE_ALL
date: 3 months ago
:::::: branch date: 7 hours ago
:::::: commit date: 3 months ago
config: arm-randconfig-c002-20230205 (https://download.01.org/0day-ci/archive/20230208/202302081230.Y4hmOpkz-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d539fee9f825b0c8eac049732c83562b28a483b5
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout d539fee9f825b0c8eac049732c83562b28a483b5
# save the config file
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error' olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error'
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
gcc_analyzer warnings: (new ones prefixed by >>)
lib/math/div64.c: In function 'mul_u64_u64_div_u64':
lib/math/div64.c:199:27: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
199 | u64 res = 0, div, rem;
| ^~~
'mul_u64_u64_div_u64': event 1
|
| 199 | u64 res = 0, div, rem;
| | ^~~
| | |
| | (1) use of uninitialized value '<unknown>' here
|
>> lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]
226 | b >>= shift;
| ~~^~~~~~~~~
'mul_u64_u64_div_u64': events 1-4
|
| 197 | u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
| | ^~~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'mul_u64_u64_div_u64'
|......
| 203 | if (ilog2(a) + ilog2(b) > 62) {
| | ~
| | |
| | (2) following 'true' branch...
|......
| 219 | div = div64_u64_rem(b, c, &rem);
| | ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
| | | |
| | | (4) calling 'div64_u64_rem' from 'mul_u64_u64_div_u64'
| | (3) ...to here
|
+--> 'div64_u64_rem': events 5-7
|
| 104 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
| | ^~~~~~~~~~~~~
| | |
| | (5) entry to 'div64_u64_rem'
|......
| 109 | if (high == 0) {
| | ~
| | |
| | (6) following 'true' branch (when 'high == 0')...
| 110 | u32 rem32;
| | ~~~
| | |
| | (7) ...to here
|
<------+
|
'mul_u64_u64_div_u64': events 8-13
|
| 219 | div = div64_u64_rem(b, c, &rem);
| | ^~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (8) returning to 'mul_u64_u64_div_u64' from 'div64_u64_rem'
|......
| 224 | if (shift > 0) {
| | ~
| | |
| | (9) following 'true' branch (when 'shift > 0')...
| 225 | /* drop precision */
| 226 | b >>= shift;
| | ~~~~~~~~~~~
| | | |
| | | (11) following 'true' branch...
| | | (12) ...to here
| | | (13) shift by count '64' here
| | (10) ...to here
|
vim +226 lib/math/div64.c
3dc167ba5729dd Oleg Nesterov 2020-05-19 195
3dc167ba5729dd Oleg Nesterov 2020-05-19 196 #ifndef mul_u64_u64_div_u64
3dc167ba5729dd Oleg Nesterov 2020-05-19 197 u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
3dc167ba5729dd Oleg Nesterov 2020-05-19 198 {
3dc167ba5729dd Oleg Nesterov 2020-05-19 199 u64 res = 0, div, rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 200 int shift;
3dc167ba5729dd Oleg Nesterov 2020-05-19 201
3dc167ba5729dd Oleg Nesterov 2020-05-19 202 /* can a * b overflow ? */
3dc167ba5729dd Oleg Nesterov 2020-05-19 203 if (ilog2(a) + ilog2(b) > 62) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 204 /*
3dc167ba5729dd Oleg Nesterov 2020-05-19 205 * (b * a) / c is equal to
3dc167ba5729dd Oleg Nesterov 2020-05-19 206 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 207 * (b / c) * a +
3dc167ba5729dd Oleg Nesterov 2020-05-19 208 * (b % c) * a / c
3dc167ba5729dd Oleg Nesterov 2020-05-19 209 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 210 * if nothing overflows. Can the 1st multiplication
3dc167ba5729dd Oleg Nesterov 2020-05-19 211 * overflow? Yes, but we do not care: this can only
3dc167ba5729dd Oleg Nesterov 2020-05-19 212 * happen if the end result can't fit in u64 anyway.
3dc167ba5729dd Oleg Nesterov 2020-05-19 213 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 214 * So the code below does
3dc167ba5729dd Oleg Nesterov 2020-05-19 215 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 216 * res = (b / c) * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 217 * b = b % c;
3dc167ba5729dd Oleg Nesterov 2020-05-19 218 */
3dc167ba5729dd Oleg Nesterov 2020-05-19 219 div = div64_u64_rem(b, c, &rem);
3dc167ba5729dd Oleg Nesterov 2020-05-19 220 res = div * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 221 b = rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 222
3dc167ba5729dd Oleg Nesterov 2020-05-19 223 shift = ilog2(a) + ilog2(b) - 62;
3dc167ba5729dd Oleg Nesterov 2020-05-19 224 if (shift > 0) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 225 /* drop precision */
3dc167ba5729dd Oleg Nesterov 2020-05-19 @226 b >>= shift;
:::::: The code at line 226 was first introduced by commit
:::::: 3dc167ba5729ddd2d8e3fa1841653792c295d3f1 sched/cputime: Improve cputime_adjust()
:::::: TO: Oleg Nesterov <oleg@redhat.com>
:::::: CC: Peter Zijlstra <peterz@infradead.org>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
^ permalink raw reply [flat|nested] 3+ messages in thread
* lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64')
@ 2023-04-02 7:52 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-04-02 7:52 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp
::::::
:::::: Manual check reason: "low confidence bisect report"
:::::: Manual check reason: "low confidence static check first_new_problem: lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: "Seung-Woo Kim" <sw0312.kim@samsung.com>
CC: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
CC: Florian Fainelli <f.fainelli@gmail.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 00c7b5f4ddc5b346df62b757ec73f9357bb452af
commit: d539fee9f825b0c8eac049732c83562b28a483b5 ARM: 9253/1: ubsan: select ARCH_HAS_UBSAN_SANITIZE_ALL
date: 5 months ago
:::::: branch date: 11 hours ago
:::::: commit date: 5 months ago
config: arm-randconfig-c002-20230402 (https://download.01.org/0day-ci/archive/20230402/202304021558.M73RQVg1-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d539fee9f825b0c8eac049732c83562b28a483b5
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout d539fee9f825b0c8eac049732c83562b28a483b5
# save the config file
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error' olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error'
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/r/202304021558.M73RQVg1-lkp@intel.com/
gcc_analyzer warnings: (new ones prefixed by >>)
lib/math/div64.c: In function 'div64_u64_rem':
lib/math/div64.c:110:21: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
110 | u32 rem32;
| ^~~~~
'mul_u64_u64_div_u64': events 1-4
|
| 197 | u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
| | ^~~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'mul_u64_u64_div_u64'
|......
| 203 | if (ilog2(a) + ilog2(b) > 62) {
| | ~
| | |
| | (2) following 'true' branch...
|......
| 219 | div = div64_u64_rem(b, c, &rem);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (3) ...to here
| | (4) calling 'div64_u64_rem' from 'mul_u64_u64_div_u64'
|
+--> 'div64_u64_rem': events 5-8
|
| 104 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
| | ^~~~~~~~~~~~~
| | |
| | (5) entry to 'div64_u64_rem'
|......
| 109 | if (high == 0) {
| | ~
| | |
| | (6) following 'true' branch (when 'high == 0')...
| 110 | u32 rem32;
| | ~~~~~
| | |
| | (7) ...to here
| | (8) use of uninitialized value '<unknown>' here
|
lib/math/div64.c: In function 'mul_u64_u64_div_u64':
lib/math/div64.c:199:27: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
199 | u64 res = 0, div, rem;
| ^~~
'mul_u64_u64_div_u64': event 1
|
| 199 | u64 res = 0, div, rem;
| | ^~~
| | |
| | (1) use of uninitialized value '<unknown>' here
|
>> lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]
226 | b >>= shift;
| ~~^~~~~~~~~
'mul_u64_u64_div_u64': event 1
|
| 197 | u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
| | ^~~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'mul_u64_u64_div_u64'
|
'mul_u64_u64_div_u64': event 2
|
|include/linux/log2.h:160:35:
| 157 | ( \
| | ~~~
| 158 | __builtin_constant_p(n) ? \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 159 | ((n) < 2 ? 0 : \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 160 | 63 - __builtin_clzll(n)) : \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
| | |
| | (2) following 'false' branch...
| 161 | (sizeof(n) <= 4) ? \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 162 | __ilog2_u32(n) : \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 163 | __ilog2_u64(n) \
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 164 | )
| | ~
lib/math/div64.c:203:13: note: in expansion of macro 'ilog2'
| 203 | if (ilog2(a) + ilog2(b) > 62) {
| | ^~~~~
|
'mul_u64_u64_div_u64': events 3-5
|
|include/asm-generic/bitops/fls64.h:21:21:
| 21 | __u32 h = x >> 32;
| | ~~^~~~~
| | |
| | (3) ...to here
| 22 | if (h)
| | ~
| | |
| | (4) following 'false' branch (when 'h == 0')...
| 23 | return fls(h) + 32;
| 24 | return fls(x);
| | ~~~~~~
| | |
| | (5) ...to here
|
'mul_u64_u64_div_u64': event 6
|
|include/asm-generic/bitops/builtin-fls.h:14:53:
| 14 | return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
| | |
| | (6) following 'false' branch...
|
'mul_u64_u64_div_u64': event 7
|
|include/linux/log2.h:32:25:
| 32 | return fls64(n) - 1;
| | ~~~~~~~~~^~~
| | |
| | (7) ...to here
|
'mul_u64_u64_div_u64': events 8-10
|
|lib/math/div64.c:203:12:
| 203 | if (ilog2(a) + ilog2(b) > 62) {
| | ^
| | |
| | (8) following 'true' branch...
|......
| 219 | div = div64_u64_rem(b, c, &rem);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (9) ...to here
| | (10) calling 'div64_u64_rem' from 'mul_u64_u64_div_u64'
|
+--> 'div64_u64_rem': events 11-14
|
| 104 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
| | ^~~~~~~~~~~~~
| | |
| | (11) entry to 'div64_u64_rem'
|......
| 109 | if (high == 0) {
| | ~
| | |
| | (12) following 'true' branch (when 'high == 0')...
| 110 | u32 rem32;
| | ~~~~~
| | |
| | (13) ...to here
| 111 | quot = div_u64_rem(dividend, divisor, &rem32);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (14) calling 'div_u64_rem' from 'div64_u64_rem'
vim +226 lib/math/div64.c
3dc167ba5729dd Oleg Nesterov 2020-05-19 195
3dc167ba5729dd Oleg Nesterov 2020-05-19 196 #ifndef mul_u64_u64_div_u64
3dc167ba5729dd Oleg Nesterov 2020-05-19 197 u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
3dc167ba5729dd Oleg Nesterov 2020-05-19 198 {
3dc167ba5729dd Oleg Nesterov 2020-05-19 199 u64 res = 0, div, rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 200 int shift;
3dc167ba5729dd Oleg Nesterov 2020-05-19 201
3dc167ba5729dd Oleg Nesterov 2020-05-19 202 /* can a * b overflow ? */
3dc167ba5729dd Oleg Nesterov 2020-05-19 203 if (ilog2(a) + ilog2(b) > 62) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 204 /*
3dc167ba5729dd Oleg Nesterov 2020-05-19 205 * (b * a) / c is equal to
3dc167ba5729dd Oleg Nesterov 2020-05-19 206 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 207 * (b / c) * a +
3dc167ba5729dd Oleg Nesterov 2020-05-19 208 * (b % c) * a / c
3dc167ba5729dd Oleg Nesterov 2020-05-19 209 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 210 * if nothing overflows. Can the 1st multiplication
3dc167ba5729dd Oleg Nesterov 2020-05-19 211 * overflow? Yes, but we do not care: this can only
3dc167ba5729dd Oleg Nesterov 2020-05-19 212 * happen if the end result can't fit in u64 anyway.
3dc167ba5729dd Oleg Nesterov 2020-05-19 213 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 214 * So the code below does
3dc167ba5729dd Oleg Nesterov 2020-05-19 215 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 216 * res = (b / c) * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 217 * b = b % c;
3dc167ba5729dd Oleg Nesterov 2020-05-19 218 */
3dc167ba5729dd Oleg Nesterov 2020-05-19 219 div = div64_u64_rem(b, c, &rem);
3dc167ba5729dd Oleg Nesterov 2020-05-19 220 res = div * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 221 b = rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 222
3dc167ba5729dd Oleg Nesterov 2020-05-19 223 shift = ilog2(a) + ilog2(b) - 62;
3dc167ba5729dd Oleg Nesterov 2020-05-19 224 if (shift > 0) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 225 /* drop precision */
3dc167ba5729dd Oleg Nesterov 2020-05-19 @226 b >>= shift;
:::::: The code at line 226 was first introduced by commit
:::::: 3dc167ba5729ddd2d8e3fa1841653792c295d3f1 sched/cputime: Improve cputime_adjust()
:::::: TO: Oleg Nesterov <oleg@redhat.com>
:::::: CC: Peter Zijlstra <peterz@infradead.org>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
^ permalink raw reply [flat|nested] 3+ messages in thread
* lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64')
@ 2023-02-06 9:42 kernel test robot
0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-02-06 9:42 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp
::::::
:::::: Manual check reason: "low confidence bisect report"
:::::: Manual check reason: "low confidence static check first_new_problem: lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: "Seung-Woo Kim" <sw0312.kim@samsung.com>
CC: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
CC: Florian Fainelli <f.fainelli@gmail.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d2d11f342b179f1894a901f143ec7c008caba43e
commit: d539fee9f825b0c8eac049732c83562b28a483b5 ARM: 9253/1: ubsan: select ARCH_HAS_UBSAN_SANITIZE_ALL
date: 3 months ago
:::::: branch date: 8 hours ago
:::::: commit date: 3 months ago
config: arm-randconfig-c002-20230205 (https://download.01.org/0day-ci/archive/20230206/202302061756.eUpw7mEJ-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d539fee9f825b0c8eac049732c83562b28a483b5
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout d539fee9f825b0c8eac049732c83562b28a483b5
# save the config file
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error' olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error'
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
gcc_analyzer warnings: (new ones prefixed by >>)
lib/math/div64.c: In function 'mul_u64_u64_div_u64':
lib/math/div64.c:199:27: warning: use of uninitialized value '<unknown>' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
199 | u64 res = 0, div, rem;
| ^~~
'mul_u64_u64_div_u64': event 1
|
| 199 | u64 res = 0, div, rem;
| | ^~~
| | |
| | (1) use of uninitialized value '<unknown>' here
|
>> lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]
226 | b >>= shift;
| ~~^~~~~~~~~
'mul_u64_u64_div_u64': events 1-4
|
| 197 | u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
| | ^~~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'mul_u64_u64_div_u64'
|......
| 203 | if (ilog2(a) + ilog2(b) > 62) {
| | ~
| | |
| | (2) following 'true' branch...
|......
| 219 | div = div64_u64_rem(b, c, &rem);
| | ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
| | | |
| | | (4) calling 'div64_u64_rem' from 'mul_u64_u64_div_u64'
| | (3) ...to here
|
+--> 'div64_u64_rem': events 5-7
|
| 104 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
| | ^~~~~~~~~~~~~
| | |
| | (5) entry to 'div64_u64_rem'
|......
| 109 | if (high == 0) {
| | ~
| | |
| | (6) following 'true' branch (when 'high == 0')...
| 110 | u32 rem32;
| | ~~~
| | |
| | (7) ...to here
|
<------+
|
'mul_u64_u64_div_u64': events 8-13
|
| 219 | div = div64_u64_rem(b, c, &rem);
| | ^~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (8) returning to 'mul_u64_u64_div_u64' from 'div64_u64_rem'
|......
| 224 | if (shift > 0) {
| | ~
| | |
| | (9) following 'true' branch (when 'shift > 0')...
| 225 | /* drop precision */
| 226 | b >>= shift;
| | ~~~~~~~~~~~
| | | |
| | | (11) following 'true' branch...
| | | (12) ...to here
| | | (13) shift by count '64' here
| | (10) ...to here
|
vim +226 lib/math/div64.c
3dc167ba5729dd Oleg Nesterov 2020-05-19 195
3dc167ba5729dd Oleg Nesterov 2020-05-19 196 #ifndef mul_u64_u64_div_u64
3dc167ba5729dd Oleg Nesterov 2020-05-19 197 u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c)
3dc167ba5729dd Oleg Nesterov 2020-05-19 198 {
3dc167ba5729dd Oleg Nesterov 2020-05-19 199 u64 res = 0, div, rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 200 int shift;
3dc167ba5729dd Oleg Nesterov 2020-05-19 201
3dc167ba5729dd Oleg Nesterov 2020-05-19 202 /* can a * b overflow ? */
3dc167ba5729dd Oleg Nesterov 2020-05-19 203 if (ilog2(a) + ilog2(b) > 62) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 204 /*
3dc167ba5729dd Oleg Nesterov 2020-05-19 205 * (b * a) / c is equal to
3dc167ba5729dd Oleg Nesterov 2020-05-19 206 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 207 * (b / c) * a +
3dc167ba5729dd Oleg Nesterov 2020-05-19 208 * (b % c) * a / c
3dc167ba5729dd Oleg Nesterov 2020-05-19 209 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 210 * if nothing overflows. Can the 1st multiplication
3dc167ba5729dd Oleg Nesterov 2020-05-19 211 * overflow? Yes, but we do not care: this can only
3dc167ba5729dd Oleg Nesterov 2020-05-19 212 * happen if the end result can't fit in u64 anyway.
3dc167ba5729dd Oleg Nesterov 2020-05-19 213 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 214 * So the code below does
3dc167ba5729dd Oleg Nesterov 2020-05-19 215 *
3dc167ba5729dd Oleg Nesterov 2020-05-19 216 * res = (b / c) * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 217 * b = b % c;
3dc167ba5729dd Oleg Nesterov 2020-05-19 218 */
3dc167ba5729dd Oleg Nesterov 2020-05-19 219 div = div64_u64_rem(b, c, &rem);
3dc167ba5729dd Oleg Nesterov 2020-05-19 220 res = div * a;
3dc167ba5729dd Oleg Nesterov 2020-05-19 221 b = rem;
3dc167ba5729dd Oleg Nesterov 2020-05-19 222
3dc167ba5729dd Oleg Nesterov 2020-05-19 223 shift = ilog2(a) + ilog2(b) - 62;
3dc167ba5729dd Oleg Nesterov 2020-05-19 224 if (shift > 0) {
3dc167ba5729dd Oleg Nesterov 2020-05-19 225 /* drop precision */
3dc167ba5729dd Oleg Nesterov 2020-05-19 @226 b >>= shift;
:::::: The code at line 226 was first introduced by commit
:::::: 3dc167ba5729ddd2d8e3fa1841653792c295d3f1 sched/cputime: Improve cputime_adjust()
:::::: TO: Oleg Nesterov <oleg@redhat.com>
:::::: CC: Peter Zijlstra <peterz@infradead.org>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-02 7:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 4:56 lib/math/div64.c:226:27: warning: shift by count ('64') >= precision of type ('64') kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2023-04-02 7:52 kernel test robot
2023-02-06 9:42 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.