Revision c4e18497d8fd92eef2c6e7eadcc1a107ccd115ea authored by Guenter Roeck on 20 December 2012, 23:05:42 UTC, committed by Linus Torvalds on 21 December 2012, 01:40:20 UTC
Commit 263a523d18bc ("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>
1 parent 154b454
File | Mode | Size |
---|---|---|
Kconfig | -rw-r--r-- | 15.0 KB |
Kconfig.debug | -rw-r--r-- | 1015 bytes |
Makefile | -rw-r--r-- | 2.0 KB |
backing-dev.c | -rw-r--r-- | 21.2 KB |
balloon_compaction.c | -rw-r--r-- | 9.6 KB |
bootmem.c | -rw-r--r-- | 20.8 KB |
bounce.c | -rw-r--r-- | 6.6 KB |
cleancache.c | -rw-r--r-- | 6.5 KB |
compaction.c | -rw-r--r-- | 34.3 KB |
debug-pagealloc.c | -rw-r--r-- | 2.1 KB |
dmapool.c | -rw-r--r-- | 13.1 KB |
fadvise.c | -rw-r--r-- | 3.6 KB |
failslab.c | -rw-r--r-- | 1.3 KB |
filemap.c | -rw-r--r-- | 67.3 KB |
filemap_xip.c | -rw-r--r-- | 11.3 KB |
fremap.c | -rw-r--r-- | 6.8 KB |
frontswap.c | -rw-r--r-- | 10.3 KB |
highmem.c | -rw-r--r-- | 9.9 KB |
huge_memory.c | -rw-r--r-- | 73.3 KB |
hugetlb.c | -rw-r--r-- | 82.4 KB |
hugetlb_cgroup.c | -rw-r--r-- | 10.7 KB |
hwpoison-inject.c | -rw-r--r-- | 3.3 KB |
init-mm.c | -rw-r--r-- | 619 bytes |
internal.h | -rw-r--r-- | 11.2 KB |
interval_tree.c | -rw-r--r-- | 3.2 KB |
kmemcheck.c | -rw-r--r-- | 2.8 KB |
kmemleak-test.c | -rw-r--r-- | 3.3 KB |
kmemleak.c | -rw-r--r-- | 52.5 KB |
ksm.c | -rw-r--r-- | 55.2 KB |
maccess.c | -rw-r--r-- | 1.6 KB |
madvise.c | -rw-r--r-- | 11.9 KB |
memblock.c | -rw-r--r-- | 29.0 KB |
memcontrol.c | -rw-r--r-- | 178.6 KB |
memory-failure.c | -rw-r--r-- | 42.3 KB |
memory.c | -rw-r--r-- | 113.6 KB |
memory_hotplug.c | -rw-r--r-- | 35.7 KB |
mempolicy.c | -rw-r--r-- | 70.9 KB |
mempool.c | -rw-r--r-- | 10.5 KB |
migrate.c | -rw-r--r-- | 44.0 KB |
mincore.c | -rw-r--r-- | 7.8 KB |
mlock.c | -rw-r--r-- | 15.5 KB |
mm_init.c | -rw-r--r-- | 3.7 KB |
mmap.c | -rw-r--r-- | 80.6 KB |
mmu_context.c | -rw-r--r-- | 1.4 KB |
mmu_notifier.c | -rw-r--r-- | 9.4 KB |
mmzone.c | -rw-r--r-- | 1.9 KB |
mprotect.c | -rw-r--r-- | 10.2 KB |
mremap.c | -rw-r--r-- | 14.3 KB |
msync.c | -rw-r--r-- | 2.4 KB |
nobootmem.c | -rw-r--r-- | 11.2 KB |
nommu.c | -rw-r--r-- | 51.3 KB |
oom_kill.c | -rw-r--r-- | 19.4 KB |
page-writeback.c | -rw-r--r-- | 69.1 KB |
page_alloc.c | -rw-r--r-- | 170.8 KB |
page_cgroup.c | -rw-r--r-- | 11.9 KB |
page_io.c | -rw-r--r-- | 6.8 KB |
page_isolation.c | -rw-r--r-- | 7.6 KB |
pagewalk.c | -rw-r--r-- | 5.7 KB |
percpu-km.c | -rw-r--r-- | 2.8 KB |
percpu-vm.c | -rw-r--r-- | 12.9 KB |
percpu.c | -rw-r--r-- | 57.1 KB |
pgtable-generic.c | -rw-r--r-- | 4.6 KB |
process_vm_access.c | -rw-r--r-- | 13.3 KB |
quicklist.c | -rw-r--r-- | 2.4 KB |
readahead.c | -rw-r--r-- | 16.1 KB |
rmap.c | -rw-r--r-- | 51.6 KB |
shmem.c | -rw-r--r-- | 76.8 KB |
slab.c | -rw-r--r-- | 117.7 KB |
slab.h | -rw-r--r-- | 6.2 KB |
slab_common.c | -rw-r--r-- | 11.1 KB |
slob.c | -rw-r--r-- | 15.3 KB |
slub.c | -rw-r--r-- | 129.0 KB |
sparse-vmemmap.c | -rw-r--r-- | 5.9 KB |
sparse.c | -rw-r--r-- | 20.7 KB |
swap.c | -rw-r--r-- | 23.1 KB |
swap_state.c | -rw-r--r-- | 10.3 KB |
swapfile.c | -rw-r--r-- | 63.1 KB |
truncate.c | -rw-r--r-- | 18.9 KB |
util.c | -rw-r--r-- | 9.1 KB |
vmalloc.c | -rw-r--r-- | 66.0 KB |
vmscan.c | -rw-r--r-- | 100.3 KB |
vmstat.c | -rw-r--r-- | 33.9 KB |
Computing file changes ...