aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha/lib
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2006-11-15 00:14:53 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:23:01 -0500
commit9be259aae5264511fe0a8b5e3d6711e0fd1d55df (patch)
treed424fd156edc0568a1d47b9322b1159202be109b /arch/alpha/lib
parent2bc357987a6510e61d33f3b20fa989fb2b6a10b8 (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>
Diffstat (limited to 'arch/alpha/lib')
-rw-r--r--arch/alpha/lib/checksum.c37
-rw-r--r--arch/alpha/lib/csum_partial_copy.c31
2 files changed, 26 insertions, 42 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 */
44unsigned 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
55unsigned 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 */
149unsigned 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 */
166unsigned 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
177EXPORT_SYMBOL(csum_partial); 174EXPORT_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 */
183unsigned 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
332static unsigned int 332__wsum
333do_csum_partial_copy_from_user(const char __user *src, char *dst, int len, 333csum_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
373unsigned int
374csum_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
386unsigned int 373__wsum
387csum_partial_copy_nocheck(const char __user *src, char *dst, int len, 374csum_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}