aboutsummaryrefslogtreecommitdiffstats
path: root/lib/checksum.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2009-06-23 15:22:58 -0400
committerArnd Bergmann <arnd@arndb.de>2009-11-03 10:06:52 -0500
commitc44ba9f6684946b156335da6a6d55f0b8cf7cb72 (patch)
tree8a24ba039b08fc8bb95a670e33ef7312443576da /lib/checksum.c
parentb6727b12dd2ffb4a890eb5b13a298230c29ba45d (diff)
lib/checksum.c: use 32-bit arithmetic consistently
The use of 'unsigned long' variables in the 32-bit part of do_csum() is confusing at best, and potentially broken for long input on 64-bit machines. This changes the code to use 'unsigned int' instead, which makes the code behave in the same (correct) way on both 32 and 64 bit machines. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'lib/checksum.c')
-rw-r--r--lib/checksum.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/checksum.c b/lib/checksum.c
index b2e2fd468461..886b48db4f28 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -37,7 +37,7 @@
37 37
38#include <asm/byteorder.h> 38#include <asm/byteorder.h>
39 39
40static inline unsigned short from32to16(unsigned long x) 40static inline unsigned short from32to16(unsigned int x)
41{ 41{
42 /* add up 16-bit and 16-bit for 16+c bit */ 42 /* add up 16-bit and 16-bit for 16+c bit */
43 x = (x & 0xffff) + (x >> 16); 43 x = (x & 0xffff) + (x >> 16);
@@ -49,7 +49,7 @@ static inline unsigned short from32to16(unsigned long x)
49static unsigned int do_csum(const unsigned char *buff, int len) 49static unsigned int do_csum(const unsigned char *buff, int len)
50{ 50{
51 int odd, count; 51 int odd, count;
52 unsigned long result = 0; 52 unsigned int result = 0;
53 53
54 if (len <= 0) 54 if (len <= 0)
55 goto out; 55 goto out;
@@ -73,9 +73,9 @@ static unsigned int do_csum(const unsigned char *buff, int len)
73 } 73 }
74 count >>= 1; /* nr of 32-bit words.. */ 74 count >>= 1; /* nr of 32-bit words.. */
75 if (count) { 75 if (count) {
76 unsigned long carry = 0; 76 unsigned int carry = 0;
77 do { 77 do {
78 unsigned long w = *(unsigned int *) buff; 78 unsigned int w = *(unsigned int *) buff;
79 count--; 79 count--;
80 buff += 4; 80 buff += 4;
81 result += carry; 81 result += carry;