]> git.baikalelectronics.ru Git - kernel.git/commit
linux/kernel.h: Fix warning seen with W=1 due to change in DIV_ROUND_CLOSEST
authorGuenter Roeck <linux@roeck-us.net>
Wed, 19 Sep 2012 03:42:31 +0000 (20:42 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 19 Sep 2012 13:51:25 +0000 (06:51 -0700)
commit8dbe61dda0f037c70fb41e29937a616812531e9d
tree085d8f549b1d133b00363535afe6b9e510dc9718
parent9817d41755adfa66cedfbcd6ce5dc6361fa5ed5a
linux/kernel.h: Fix warning seen with W=1 due to change in DIV_ROUND_CLOSEST

After commit c83cb4a8 (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: Guenter Roeck <linux@roeck-us.net>
Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
include/linux/kernel.h