diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2006-11-15 00:14:53 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:23:01 -0500 |
commit | 9be259aae5264511fe0a8b5e3d6711e0fd1d55df (patch) | |
tree | d424fd156edc0568a1d47b9322b1159202be109b | |
parent | 2bc357987a6510e61d33f3b20fa989fb2b6a10b8 (diff) |
[NET]: Alpha checksum annotations and cleanups.
* sanitize prototypes and annotate
* kill useless access_ok() in csum_partial_copy_from_user() (the only
caller checks it already).
* do_csum_partial_copy_from_user() is not needed now
* replace htons(len) with len << 8 - they are the same wrt checksums
on little-endian.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | arch/alpha/lib/checksum.c | 37 | ||||
-rw-r--r-- | arch/alpha/lib/csum_partial_copy.c | 31 | ||||
-rw-r--r-- | include/asm-alpha/checksum.h | 34 |
3 files changed, 42 insertions, 60 deletions
diff --git a/arch/alpha/lib/checksum.c b/arch/alpha/lib/checksum.c index 89044e6385fe..ab3761c437a8 100644 --- a/arch/alpha/lib/checksum.c +++ b/arch/alpha/lib/checksum.c | |||
@@ -41,28 +41,25 @@ static inline unsigned short from64to16(unsigned long x) | |||
41 | * computes the checksum of the TCP/UDP pseudo-header | 41 | * computes the checksum of the TCP/UDP pseudo-header |
42 | * returns a 16-bit checksum, already complemented. | 42 | * returns a 16-bit checksum, already complemented. |
43 | */ | 43 | */ |
44 | unsigned short int csum_tcpudp_magic(unsigned long saddr, | 44 | __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
45 | unsigned long daddr, | ||
46 | unsigned short len, | 45 | unsigned short len, |
47 | unsigned short proto, | 46 | unsigned short proto, |
48 | unsigned int sum) | 47 | __wsum sum) |
49 | { | 48 | { |
50 | return ~from64to16(saddr + daddr + sum + | 49 | return (__force __sum16)~from64to16( |
51 | ((unsigned long) ntohs(len) << 16) + | 50 | (__force u64)saddr + (__force u64)daddr + |
52 | ((unsigned long) proto << 8)); | 51 | (__force u64)sum + ((len + proto) << 8)); |
53 | } | 52 | } |
54 | 53 | ||
55 | unsigned int csum_tcpudp_nofold(unsigned long saddr, | 54 | __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, |
56 | unsigned long daddr, | ||
57 | unsigned short len, | 55 | unsigned short len, |
58 | unsigned short proto, | 56 | unsigned short proto, |
59 | unsigned int sum) | 57 | __wsum sum) |
60 | { | 58 | { |
61 | unsigned long result; | 59 | unsigned long result; |
62 | 60 | ||
63 | result = (saddr + daddr + sum + | 61 | result = (__force u64)saddr + (__force u64)daddr + |
64 | ((unsigned long) ntohs(len) << 16) + | 62 | (__force u64)sum + ((len + proto) << 8); |
65 | ((unsigned long) proto << 8)); | ||
66 | 63 | ||
67 | /* Fold down to 32-bits so we don't lose in the typedef-less | 64 | /* Fold down to 32-bits so we don't lose in the typedef-less |
68 | network stack. */ | 65 | network stack. */ |
@@ -70,7 +67,7 @@ unsigned int csum_tcpudp_nofold(unsigned long saddr, | |||
70 | result = (result & 0xffffffff) + (result >> 32); | 67 | result = (result & 0xffffffff) + (result >> 32); |
71 | /* 33 to 32 */ | 68 | /* 33 to 32 */ |
72 | result = (result & 0xffffffff) + (result >> 32); | 69 | result = (result & 0xffffffff) + (result >> 32); |
73 | return result; | 70 | return (__force __wsum)result; |
74 | } | 71 | } |
75 | 72 | ||
76 | /* | 73 | /* |
@@ -146,9 +143,9 @@ out: | |||
146 | * This is a version of ip_compute_csum() optimized for IP headers, | 143 | * This is a version of ip_compute_csum() optimized for IP headers, |
147 | * which always checksum on 4 octet boundaries. | 144 | * which always checksum on 4 octet boundaries. |
148 | */ | 145 | */ |
149 | unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) | 146 | __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
150 | { | 147 | { |
151 | return ~do_csum(iph,ihl*4); | 148 | return (__force __sum16)~do_csum(iph,ihl*4); |
152 | } | 149 | } |
153 | 150 | ||
154 | /* | 151 | /* |
@@ -163,15 +160,15 @@ unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) | |||
163 | * | 160 | * |
164 | * it's best to have buff aligned on a 32-bit boundary | 161 | * it's best to have buff aligned on a 32-bit boundary |
165 | */ | 162 | */ |
166 | unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) | 163 | __wsum csum_partial(const void *buff, int len, __wsum sum) |
167 | { | 164 | { |
168 | unsigned long result = do_csum(buff, len); | 165 | unsigned long result = do_csum(buff, len); |
169 | 166 | ||
170 | /* add in old sum, and carry.. */ | 167 | /* add in old sum, and carry.. */ |
171 | result += sum; | 168 | result += (__force u32)sum; |
172 | /* 32+c bits -> 32 bits */ | 169 | /* 32+c bits -> 32 bits */ |
173 | result = (result & 0xffffffff) + (result >> 32); | 170 | result = (result & 0xffffffff) + (result >> 32); |
174 | return result; | 171 | return (__force __wsum)result; |
175 | } | 172 | } |
176 | 173 | ||
177 | EXPORT_SYMBOL(csum_partial); | 174 | EXPORT_SYMBOL(csum_partial); |
@@ -180,7 +177,7 @@ EXPORT_SYMBOL(csum_partial); | |||
180 | * this routine is used for miscellaneous IP-like checksums, mainly | 177 | * this routine is used for miscellaneous IP-like checksums, mainly |
181 | * in icmp.c | 178 | * in icmp.c |
182 | */ | 179 | */ |
183 | unsigned short ip_compute_csum(unsigned char * buff, int len) | 180 | __sum16 ip_compute_csum(const void *buff, int len) |
184 | { | 181 | { |
185 | return ~from64to16(do_csum(buff,len)); | 182 | return (__force __sum16)~from64to16(do_csum(buff,len)); |
186 | } | 183 | } |
diff --git a/arch/alpha/lib/csum_partial_copy.c b/arch/alpha/lib/csum_partial_copy.c index a37948f3037a..4ca75c74ce90 100644 --- a/arch/alpha/lib/csum_partial_copy.c +++ b/arch/alpha/lib/csum_partial_copy.c | |||
@@ -329,11 +329,11 @@ csum_partial_cfu_unaligned(const unsigned long __user * src, | |||
329 | return checksum; | 329 | return checksum; |
330 | } | 330 | } |
331 | 331 | ||
332 | static unsigned int | 332 | __wsum |
333 | do_csum_partial_copy_from_user(const char __user *src, char *dst, int len, | 333 | csum_partial_copy_from_user(const void __user *src, void *dst, int len, |
334 | unsigned int sum, int *errp) | 334 | __wsum sum, int *errp) |
335 | { | 335 | { |
336 | unsigned long checksum = (unsigned) sum; | 336 | unsigned long checksum = (__force u32) sum; |
337 | unsigned long soff = 7 & (unsigned long) src; | 337 | unsigned long soff = 7 & (unsigned long) src; |
338 | unsigned long doff = 7 & (unsigned long) dst; | 338 | unsigned long doff = 7 & (unsigned long) dst; |
339 | 339 | ||
@@ -367,25 +367,12 @@ do_csum_partial_copy_from_user(const char __user *src, char *dst, int len, | |||
367 | } | 367 | } |
368 | checksum = from64to16 (checksum); | 368 | checksum = from64to16 (checksum); |
369 | } | 369 | } |
370 | return checksum; | 370 | return (__force __wsum)checksum; |
371 | } | ||
372 | |||
373 | unsigned int | ||
374 | csum_partial_copy_from_user(const char __user *src, char *dst, int len, | ||
375 | unsigned int sum, int *errp) | ||
376 | { | ||
377 | if (!access_ok(VERIFY_READ, src, len)) { | ||
378 | *errp = -EFAULT; | ||
379 | memset(dst, 0, len); | ||
380 | return sum; | ||
381 | } | ||
382 | |||
383 | return do_csum_partial_copy_from_user(src, dst, len, sum, errp); | ||
384 | } | 371 | } |
385 | 372 | ||
386 | unsigned int | 373 | __wsum |
387 | csum_partial_copy_nocheck(const char __user *src, char *dst, int len, | 374 | csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum) |
388 | unsigned int sum) | ||
389 | { | 375 | { |
390 | return do_csum_partial_copy_from_user(src, dst, len, sum, NULL); | 376 | return csum_partial_copy_from_user((__force const void __user *)src, |
377 | dst, len, sum, NULL); | ||
391 | } | 378 | } |
diff --git a/include/asm-alpha/checksum.h b/include/asm-alpha/checksum.h index a5c9f08447fb..d3854bbf0a9e 100644 --- a/include/asm-alpha/checksum.h +++ b/include/asm-alpha/checksum.h | |||
@@ -7,21 +7,20 @@ | |||
7 | * This is a version of ip_compute_csum() optimized for IP headers, | 7 | * This is a version of ip_compute_csum() optimized for IP headers, |
8 | * which always checksum on 4 octet boundaries. | 8 | * which always checksum on 4 octet boundaries. |
9 | */ | 9 | */ |
10 | extern unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl); | 10 | extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * computes the checksum of the TCP/UDP pseudo-header | 13 | * computes the checksum of the TCP/UDP pseudo-header |
14 | * returns a 16-bit checksum, already complemented | 14 | * returns a 16-bit checksum, already complemented |
15 | */ | 15 | */ |
16 | extern unsigned short int csum_tcpudp_magic(unsigned long saddr, | 16 | extern __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
17 | unsigned long daddr, | ||
18 | unsigned short len, | 17 | unsigned short len, |
19 | unsigned short proto, | 18 | unsigned short proto, |
20 | unsigned int sum); | 19 | __wsum sum); |
21 | 20 | ||
22 | unsigned int csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, | 21 | __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, |
23 | unsigned short len, unsigned short proto, | 22 | unsigned short len, unsigned short proto, |
24 | unsigned int sum); | 23 | __wsum sum); |
25 | 24 | ||
26 | /* | 25 | /* |
27 | * computes the checksum of a memory block at buff, length len, | 26 | * computes the checksum of a memory block at buff, length len, |
@@ -35,7 +34,7 @@ unsigned int csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, | |||
35 | * | 34 | * |
36 | * it's best to have buff aligned on a 32-bit boundary | 35 | * it's best to have buff aligned on a 32-bit boundary |
37 | */ | 36 | */ |
38 | extern unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum); | 37 | extern __wsum csum_partial(const void *buff, int len, __wsum sum); |
39 | 38 | ||
40 | /* | 39 | /* |
41 | * the same as csum_partial, but copies from src while it | 40 | * the same as csum_partial, but copies from src while it |
@@ -44,9 +43,9 @@ extern unsigned int csum_partial(const unsigned char * buff, int len, unsigned i | |||
44 | * here even more important to align src and dst on a 32-bit (or even | 43 | * here even more important to align src and dst on a 32-bit (or even |
45 | * better 64-bit) boundary | 44 | * better 64-bit) boundary |
46 | */ | 45 | */ |
47 | unsigned int csum_partial_copy_from_user(const char __user *src, char *dst, int len, unsigned int sum, int *errp); | 46 | __wsum csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *errp); |
48 | 47 | ||
49 | unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, unsigned int sum); | 48 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum); |
50 | 49 | ||
51 | 50 | ||
52 | /* | 51 | /* |
@@ -54,24 +53,23 @@ unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, unsi | |||
54 | * in icmp.c | 53 | * in icmp.c |
55 | */ | 54 | */ |
56 | 55 | ||
57 | extern unsigned short ip_compute_csum(unsigned char * buff, int len); | 56 | extern __sum16 ip_compute_csum(const void *buff, int len); |
58 | 57 | ||
59 | /* | 58 | /* |
60 | * Fold a partial checksum without adding pseudo headers | 59 | * Fold a partial checksum without adding pseudo headers |
61 | */ | 60 | */ |
62 | 61 | ||
63 | static inline unsigned short csum_fold(unsigned int sum) | 62 | static inline __sum16 csum_fold(__wsum csum) |
64 | { | 63 | { |
64 | u32 sum = (__force u32)csum; | ||
65 | sum = (sum & 0xffff) + (sum >> 16); | 65 | sum = (sum & 0xffff) + (sum >> 16); |
66 | sum = (sum & 0xffff) + (sum >> 16); | 66 | sum = (sum & 0xffff) + (sum >> 16); |
67 | return ~sum; | 67 | return (__force __sum16)~sum; |
68 | } | 68 | } |
69 | 69 | ||
70 | #define _HAVE_ARCH_IPV6_CSUM | 70 | #define _HAVE_ARCH_IPV6_CSUM |
71 | extern unsigned short int csum_ipv6_magic(struct in6_addr *saddr, | 71 | extern __sum16 csum_ipv6_magic(const struct in6_addr *saddr, |
72 | struct in6_addr *daddr, | 72 | const struct in6_addr *daddr, |
73 | __u32 len, | 73 | __u32 len, unsigned short proto, |
74 | unsigned short proto, | 74 | __wsum sum); |
75 | unsigned int sum); | ||
76 | |||
77 | #endif | 75 | #endif |