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

[NET]: SH64 checksum annotations and cleanups.

* sanitize prototypes, annotate
* collapse csum_partial_copy
* kill csum_partial_copy_fromuser
* ntohs->shift in checksum calculation

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
c459dd90 7814e4b6

+32 -60
+1 -1
arch/sh64/kernel/sh_ksyms.c
··· 38 38 EXPORT_SYMBOL(kernel_thread); 39 39 40 40 /* Networking helper routines. */ 41 - EXPORT_SYMBOL(csum_partial_copy); 41 + EXPORT_SYMBOL(csum_partial_copy_nocheck); 42 42 43 43 EXPORT_SYMBOL(strstr); 44 44
+17 -32
arch/sh64/lib/c-checksum.c
··· 118 118 119 119 /* computes the checksum of a memory block at buff, length len, 120 120 and adds in "sum" (32-bit) */ 121 - unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum) 121 + __wsum csum_partial(const void *buff, int len, __wsum sum) 122 122 { 123 123 unsigned long long result = do_csum(buff, len); 124 124 125 125 /* add in old sum, and carry.. */ 126 - result += sum; 126 + result += (__force u32)sum; 127 127 /* 32+c bits -> 32 bits */ 128 128 result = (result & 0xffffffff) + (result >> 32); 129 129 130 130 pr_debug("csum_partial, buff %p len %d sum 0x%x result=0x%016Lx\n", 131 131 buff, len, sum, result); 132 132 133 - return result; 133 + return (__force __wsum)result; 134 134 } 135 135 136 136 /* Copy while checksumming, otherwise like csum_partial. */ 137 - unsigned int 138 - csum_partial_copy(const unsigned char *src, unsigned char *dst, int len, unsigned int sum) 137 + __wsum 138 + csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum) 139 139 { 140 140 sum = csum_partial(src, len, sum); 141 141 memcpy(dst, src, len); ··· 145 145 146 146 /* Copy from userspace and compute checksum. If we catch an exception 147 147 then zero the rest of the buffer. */ 148 - unsigned int 149 - csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst, int len, 150 - unsigned int sum, int *err_ptr) 148 + __wsum 149 + csum_partial_copy_from_user(const void __user *src, void *dst, int len, 150 + __wsum sum, int *err_ptr) 151 151 { 152 152 int missing; 153 153 ··· 166 166 } 167 167 168 168 /* Copy to userspace and compute checksum. */ 169 - unsigned int 169 + __wsum 170 170 csum_partial_copy_to_user(const unsigned char *src, unsigned char *dst, int len, 171 - unsigned int sum, int *err_ptr) 171 + __wsum sum, int *err_ptr) 172 172 { 173 173 sum = csum_partial(src, len, sum); 174 174 ··· 182 182 * This is a version of ip_compute_csum() optimized for IP headers, 183 183 * which always checksum on 4 octet boundaries. 184 184 */ 185 - unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) 185 + __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 186 186 { 187 187 pr_debug("ip_fast_csum %p,%d\n", iph, ihl); 188 188 189 - return ~do_csum(iph, ihl * 4); 189 + return (__force __sum16)~do_csum(iph, ihl * 4); 190 190 } 191 191 192 - unsigned int csum_tcpudp_nofold(unsigned long saddr, 193 - unsigned long daddr, 192 + __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 194 193 unsigned short len, 195 - unsigned short proto, unsigned int sum) 194 + unsigned short proto, __wsum sum) 196 195 { 197 196 unsigned long long result; 198 197 199 198 pr_debug("ntohs(0x%x)=0x%x\n", 0xdead, ntohs(0xdead)); 200 199 pr_debug("htons(0x%x)=0x%x\n", 0xdead, htons(0xdead)); 201 200 202 - result = ((unsigned long long) saddr + 203 - (unsigned long long) daddr + 204 - (unsigned long long) sum + 205 - ((unsigned long long) ntohs(len) << 16) + 206 - ((unsigned long long) proto << 8)); 201 + result = (__force u64) saddr + (__force u64) daddr + 202 + (__force u64) sum + ((len + proto) << 8); 207 203 208 204 /* Fold down to 32-bits so we don't loose in the typedef-less 209 205 network stack. */ ··· 211 215 pr_debug("%s saddr %x daddr %x len %x proto %x sum %x result %08Lx\n", 212 216 __FUNCTION__, saddr, daddr, len, proto, sum, result); 213 217 214 - return result; 215 - } 216 - 217 - // Post SIM: 218 - unsigned int 219 - csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, int len, unsigned int sum) 220 - { 221 - // unsigned dummy; 222 - pr_debug("csum_partial_copy_nocheck src %p dst %p len %d\n", src, dst, 223 - len); 224 - 225 - return csum_partial_copy(src, dst, len, sum); 218 + return (__wsum)result; 226 219 }
+14 -27
include/asm-sh64/checksum.h
··· 26 26 * 27 27 * it's best to have buff aligned on a 32-bit boundary 28 28 */ 29 - asmlinkage unsigned int csum_partial(const unsigned char *buff, int len, 30 - unsigned int sum); 29 + asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum); 31 30 32 31 /* 33 32 * Note: when you get a NULL pointer exception here this means someone ··· 37 38 */ 38 39 39 40 40 - unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, 41 - unsigned int sum); 41 + __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, 42 + __wsum sum); 42 43 43 - unsigned int csum_partial_copy_from_user(const char *src, char *dst, 44 - int len, int sum, int *err_ptr); 44 + __wsum csum_partial_copy_from_user(const void __user *src, void *dst, 45 + int len, __wsum sum, int *err_ptr); 45 46 46 - /* 47 - * These are the old (and unsafe) way of doing checksums, a warning message will be 48 - * printed if they are used and an exeption occurs. 49 - * 50 - * these functions should go away after some time. 51 - */ 52 - 53 - #define csum_partial_copy_fromuser csum_partial_copy 54 - 55 - unsigned int csum_partial_copy(const char *src, char *dst, int len, 56 - unsigned int sum); 57 - 58 - static inline unsigned short csum_fold(unsigned int sum) 47 + static inline __sum16 csum_fold(__wsum csum) 59 48 { 49 + u32 sum = (__force u32)csum; 60 50 sum = (sum & 0xffff) + (sum >> 16); 61 51 sum = (sum & 0xffff) + (sum >> 16); 62 - return ~(sum); 52 + return (__force __sum16)~sum; 63 53 } 64 54 65 - unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl); 55 + __sum16 ip_fast_csum(const void *iph, unsigned int ihl); 66 56 67 - unsigned long csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, 57 + __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 68 58 unsigned short len, unsigned short proto, 69 - unsigned int sum); 59 + __wsum sum); 70 60 71 61 /* 72 62 * computes the checksum of the TCP/UDP pseudo-header 73 63 * returns a 16-bit checksum, already complemented 74 64 */ 75 - static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 76 - unsigned long daddr, 65 + static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 77 66 unsigned short len, 78 67 unsigned short proto, 79 - unsigned int sum) 68 + __wsum sum) 80 69 { 81 70 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 82 71 } ··· 73 86 * this routine is used for miscellaneous IP-like checksums, mainly 74 87 * in icmp.c 75 88 */ 76 - static inline unsigned short ip_compute_csum(unsigned char * buff, int len) 89 + static inline __sum16 ip_compute_csum(const void *buff, int len) 77 90 { 78 91 return csum_fold(csum_partial(buff, len, 0)); 79 92 }