Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Al Viro and committed by
David S. Miller
9be259aa 2bc35798

+42 -60
+17 -20
arch/alpha/lib/checksum.c
··· 41 41 * computes the checksum of the TCP/UDP pseudo-header 42 42 * returns a 16-bit checksum, already complemented. 43 43 */ 44 - unsigned short int csum_tcpudp_magic(unsigned long saddr, 45 - unsigned long daddr, 44 + __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 46 45 unsigned short len, 47 46 unsigned short proto, 48 - unsigned int sum) 47 + __wsum sum) 49 48 { 50 - return ~from64to16(saddr + daddr + sum + 51 - ((unsigned long) ntohs(len) << 16) + 52 - ((unsigned long) proto << 8)); 49 + return (__force __sum16)~from64to16( 50 + (__force u64)saddr + (__force u64)daddr + 51 + (__force u64)sum + ((len + proto) << 8)); 53 52 } 54 53 55 - unsigned int csum_tcpudp_nofold(unsigned long saddr, 56 - unsigned long daddr, 54 + __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 57 55 unsigned short len, 58 56 unsigned short proto, 59 - unsigned int sum) 57 + __wsum sum) 60 58 { 61 59 unsigned long result; 62 60 63 - result = (saddr + daddr + sum + 64 - ((unsigned long) ntohs(len) << 16) + 65 - ((unsigned long) proto << 8)); 61 + result = (__force u64)saddr + (__force u64)daddr + 62 + (__force u64)sum + ((len + proto) << 8); 66 63 67 64 /* Fold down to 32-bits so we don't lose in the typedef-less 68 65 network stack. */ ··· 67 70 result = (result & 0xffffffff) + (result >> 32); 68 71 /* 33 to 32 */ 69 72 result = (result & 0xffffffff) + (result >> 32); 70 - return result; 73 + return (__force __wsum)result; 71 74 } 72 75 73 76 /* ··· 143 146 * This is a version of ip_compute_csum() optimized for IP headers, 144 147 * which always checksum on 4 octet boundaries. 145 148 */ 146 - unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl) 149 + __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 147 150 { 148 - return ~do_csum(iph,ihl*4); 151 + return (__force __sum16)~do_csum(iph,ihl*4); 149 152 } 150 153 151 154 /* ··· 160 163 * 161 164 * it's best to have buff aligned on a 32-bit boundary 162 165 */ 163 - unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum) 166 + __wsum csum_partial(const void *buff, int len, __wsum sum) 164 167 { 165 168 unsigned long result = do_csum(buff, len); 166 169 167 170 /* add in old sum, and carry.. */ 168 - result += sum; 171 + result += (__force u32)sum; 169 172 /* 32+c bits -> 32 bits */ 170 173 result = (result & 0xffffffff) + (result >> 32); 171 - return result; 174 + return (__force __wsum)result; 172 175 } 173 176 174 177 EXPORT_SYMBOL(csum_partial); ··· 177 180 * this routine is used for miscellaneous IP-like checksums, mainly 178 181 * in icmp.c 179 182 */ 180 - unsigned short ip_compute_csum(unsigned char * buff, int len) 183 + __sum16 ip_compute_csum(const void *buff, int len) 181 184 { 182 - return ~from64to16(do_csum(buff,len)); 185 + return (__force __sum16)~from64to16(do_csum(buff,len)); 183 186 }
+9 -22
arch/alpha/lib/csum_partial_copy.c
··· 329 329 return checksum; 330 330 } 331 331 332 - static unsigned int 333 - do_csum_partial_copy_from_user(const char __user *src, char *dst, int len, 334 - unsigned int sum, int *errp) 332 + __wsum 333 + csum_partial_copy_from_user(const void __user *src, void *dst, int len, 334 + __wsum sum, int *errp) 335 335 { 336 - unsigned long checksum = (unsigned) sum; 336 + unsigned long checksum = (__force u32) sum; 337 337 unsigned long soff = 7 & (unsigned long) src; 338 338 unsigned long doff = 7 & (unsigned long) dst; 339 339 ··· 367 367 } 368 368 checksum = from64to16 (checksum); 369 369 } 370 - return checksum; 370 + return (__force __wsum)checksum; 371 371 } 372 372 373 - unsigned int 374 - csum_partial_copy_from_user(const char __user *src, char *dst, int len, 375 - unsigned int sum, int *errp) 373 + __wsum 374 + csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum) 376 375 { 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 - } 385 - 386 - unsigned int 387 - csum_partial_copy_nocheck(const char __user *src, char *dst, int len, 388 - unsigned int sum) 389 - { 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 }
+16 -18
include/asm-alpha/checksum.h
··· 7 7 * This is a version of ip_compute_csum() optimized for IP headers, 8 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 13 * computes the checksum of the TCP/UDP pseudo-header 14 14 * returns a 16-bit checksum, already complemented 15 15 */ 16 - extern unsigned short int csum_tcpudp_magic(unsigned long saddr, 17 - unsigned long daddr, 16 + extern __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 18 17 unsigned short len, 19 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 22 unsigned short len, unsigned short proto, 24 - unsigned int sum); 23 + __wsum sum); 25 24 26 25 /* 27 26 * computes the checksum of a memory block at buff, length len, ··· 34 35 * 35 36 * it's best to have buff aligned on a 32-bit boundary 36 37 */ 37 - extern unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum); 38 + extern __wsum csum_partial(const void *buff, int len, __wsum sum); 38 39 39 40 /* 40 41 * the same as csum_partial, but copies from src while it ··· 43 44 * here even more important to align src and dst on a 32-bit (or even 44 45 * better 64-bit) boundary 45 46 */ 46 - unsigned int csum_partial_copy_from_user(const char __user *src, char *dst, int len, unsigned int sum, int *errp); 47 + __wsum csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *errp); 47 48 48 - unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, unsigned int sum); 49 + __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum); 49 50 50 51 51 52 /* ··· 53 54 * in icmp.c 54 55 */ 55 56 56 - extern unsigned short ip_compute_csum(unsigned char * buff, int len); 57 + extern __sum16 ip_compute_csum(const void *buff, int len); 57 58 58 59 /* 59 60 * Fold a partial checksum without adding pseudo headers 60 61 */ 61 62 62 - static inline unsigned short csum_fold(unsigned int sum) 63 + static inline __sum16 csum_fold(__wsum csum) 63 64 { 65 + u32 sum = (__force u32)csum; 64 66 sum = (sum & 0xffff) + (sum >> 16); 65 67 sum = (sum & 0xffff) + (sum >> 16); 66 - return ~sum; 68 + return (__force __sum16)~sum; 67 69 } 68 70 69 71 #define _HAVE_ARCH_IPV6_CSUM 70 - extern unsigned short int csum_ipv6_magic(struct in6_addr *saddr, 71 - struct in6_addr *daddr, 72 - __u32 len, 73 - unsigned short proto, 74 - unsigned int sum); 75 - 72 + extern __sum16 csum_ipv6_magic(const struct in6_addr *saddr, 73 + const struct in6_addr *daddr, 74 + __u32 len, unsigned short proto, 75 + __wsum sum); 76 76 #endif