Files
kernel_arpi/include/linux
Guenter Roeck c4e18497d8 linux/kernel.h: fix DIV_ROUND_CLOSEST with unsigned divisors
Commit 263a523d18 ("linux/kernel.h: Fix warning seen with W=1 due to
change in DIV_ROUND_CLOSEST") fixes a warning seen with W=1 due to
change in DIV_ROUND_CLOSEST.

Unfortunately, the C compiler converts divide operations with unsigned
divisors to unsigned, even if the dividend is signed and negative (for
example, -10 / 5U = 858993457).  The C standard says "If one operand has
unsigned int type, the other operand is converted to unsigned int", so
the compiler is not to blame.  As a result, DIV_ROUND_CLOSEST(0, 2U) and
similar operations now return bad values, since the automatic conversion
of expressions such as "0 - 2U/2" to unsigned was not taken into
account.

Fix by checking for the divisor variable type when deciding which
operation to perform.  This fixes DIV_ROUND_CLOSEST(0, 2U), but still
returns bad values for negative dividends divided by unsigned divisors.
Mark the latter case as unsupported.

One observed effect of this problem is that the s2c_hwmon driver reports
a value of 4198403 instead of 0 if the ADC reads 0.

Other impact is unpredictable.  Problem is seen if the divisor is an
unsigned variable or constant and the dividend is less than (divisor/2).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reported-by: Juergen Beisert <jbe@pengutronix.de>
Tested-by: Juergen Beisert <jbe@pengutronix.de>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: <stable@vger.kernel.org>	[3.7.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-12-20 17:40:20 -08:00
..
2012-11-26 10:19:17 -08:00
2012-12-07 17:02:47 +00:00
2012-12-19 12:46:40 -08:00
2012-11-30 12:37:36 +01:00
2012-12-02 00:05:12 +00:00
2012-11-15 00:34:23 +01:00
2012-11-08 16:58:31 +01:00
2012-11-28 11:54:40 +01:00
2012-11-22 13:43:27 +09:00
2012-11-28 21:49:02 -05:00
2012-11-28 21:49:02 -05:00
2012-12-17 20:58:12 -08:00
2012-11-08 16:58:30 +01:00
2012-11-21 10:07:48 +01:00
2012-11-23 12:23:40 +01:00
2012-12-14 13:05:26 +10:30
2012-11-21 15:09:26 -08:00
2012-11-08 11:24:46 -05:00
2012-11-20 16:15:02 +10:00
2012-12-12 17:38:33 -08:00
2012-12-14 13:06:40 +10:30
2012-12-11 17:22:27 -08:00
2012-12-17 17:15:22 -08:00
2012-11-16 14:33:04 -08:00
2012-12-18 15:02:13 -08:00
2012-12-18 15:02:14 -08:00
2012-11-15 17:20:58 -08:00