Skip to content
Snippets Groups Projects
Select Git revision
  • 263a523d18bca306016d75f5c8d5c57c37fe52fb
  • vme-testing default
  • ci-test
  • master
  • remoteproc
  • am625-sk-ov5640
  • pcal6534-upstreaming
  • lps22df-upstreaming
  • msc-upstreaming
  • imx8mp
  • iio/noa1305
  • vme-next
  • vme-next-4.14-rc4
  • v4.14-rc4
  • v4.14-rc3
  • v4.14-rc2
  • v4.14-rc1
  • v4.13
  • vme-next-4.13-rc7
  • v4.13-rc7
  • v4.13-rc6
  • v4.13-rc5
  • v4.13-rc4
  • v4.13-rc3
  • v4.13-rc2
  • v4.13-rc1
  • v4.12
  • v4.12-rc7
  • v4.12-rc6
  • v4.12-rc5
  • v4.12-rc4
  • v4.12-rc3
32 results

kernel.h

  • Guenter Roeck's avatar
    263a523d
    linux/kernel.h: Fix warning seen with W=1 due to change in DIV_ROUND_CLOSEST · 263a523d
    Guenter Roeck authored
    
    After commit b6d86d3d (Fix DIV_ROUND_CLOSEST to support negative dividends),
    the following warning is seen if the kernel is compiled with W=1 (-Wextra):
    
    warning: comparison of unsigned expression >= 0 is always true
    
    The warning is due to the test '((typeof(x))-1) >= 0', which is used to detect
    if the variable type is unsigned. Research on the web suggests that the warning
    disappears if '>' instead of '>=' is used for the comparison.
    
    Tests after changing the macro along that line show that the warning is gone,
    and that the result is still correct:
    
    i=-4: DIV_ROUND_CLOSEST(i, 2)=-2
    i=-3: DIV_ROUND_CLOSEST(i, 2)=-2
    i=-2: DIV_ROUND_CLOSEST(i, 2)=-1
    i=-1: DIV_ROUND_CLOSEST(i, 2)=-1
    i=0: DIV_ROUND_CLOSEST(i, 2)=0
    i=1: DIV_ROUND_CLOSEST(i, 2)=1
    i=2: DIV_ROUND_CLOSEST(i, 2)=1
    i=3: DIV_ROUND_CLOSEST(i, 2)=2
    i=4: DIV_ROUND_CLOSEST(i, 2)=2
    
    Code size is the same as before.
    
    Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
    Tested-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
    Acked-by: default avatarJean Delvare <khali@linux-fr.org>
    263a523d
    History
    linux/kernel.h: Fix warning seen with W=1 due to change in DIV_ROUND_CLOSEST
    Guenter Roeck authored
    
    After commit b6d86d3d (Fix DIV_ROUND_CLOSEST to support negative dividends),
    the following warning is seen if the kernel is compiled with W=1 (-Wextra):
    
    warning: comparison of unsigned expression >= 0 is always true
    
    The warning is due to the test '((typeof(x))-1) >= 0', which is used to detect
    if the variable type is unsigned. Research on the web suggests that the warning
    disappears if '>' instead of '>=' is used for the comparison.
    
    Tests after changing the macro along that line show that the warning is gone,
    and that the result is still correct:
    
    i=-4: DIV_ROUND_CLOSEST(i, 2)=-2
    i=-3: DIV_ROUND_CLOSEST(i, 2)=-2
    i=-2: DIV_ROUND_CLOSEST(i, 2)=-1
    i=-1: DIV_ROUND_CLOSEST(i, 2)=-1
    i=0: DIV_ROUND_CLOSEST(i, 2)=0
    i=1: DIV_ROUND_CLOSEST(i, 2)=1
    i=2: DIV_ROUND_CLOSEST(i, 2)=1
    i=3: DIV_ROUND_CLOSEST(i, 2)=2
    i=4: DIV_ROUND_CLOSEST(i, 2)=2
    
    Code size is the same as before.
    
    Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
    Tested-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
    Acked-by: default avatarJean Delvare <khali@linux-fr.org>