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

[NET]: M32R checksum annotations and cleanups.

* sanitize prototypes, annotate
* ntohs -> shift in checksum calculations in l-e case
* kill shift-by-16 in checksum calculations

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
85d20dee 32252996

+29 -35
+5 -7
arch/m32r/lib/csum_partial_copy.c
··· 27 27 /* 28 28 * Copy while checksumming, otherwise like csum_partial 29 29 */ 30 - unsigned int 31 - csum_partial_copy_nocheck (const unsigned char *src, unsigned char *dst, 32 - int len, unsigned int sum) 30 + __wsum 31 + csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum) 33 32 { 34 33 sum = csum_partial(src, len, sum); 35 34 memcpy(dst, src, len); ··· 41 42 * Copy from userspace and compute checksum. If we catch an exception 42 43 * then zero the rest of the buffer. 43 44 */ 44 - unsigned int 45 - csum_partial_copy_from_user (const unsigned char __user *src, 46 - unsigned char *dst, 47 - int len, unsigned int sum, int *err_ptr) 45 + __wsum 46 + csum_partial_copy_from_user (const void __user *src, void *dst, 47 + int len, __wsum sum, int *err_ptr) 48 48 { 49 49 int missing; 50 50
+24 -28
include/asm-m32r/checksum.h
··· 31 31 * 32 32 * it's best to have buff aligned on a 32-bit boundary 33 33 */ 34 - asmlinkage unsigned int csum_partial(const unsigned char *buff, 35 - int len, unsigned int sum); 34 + asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum); 36 35 37 36 /* 38 37 * The same as csum_partial, but copies from src while it checksums. ··· 39 40 * Here even more important to align src and dst on a 32-bit (or even 40 41 * better 64-bit) boundary 41 42 */ 42 - extern unsigned int csum_partial_copy_nocheck(const unsigned char *src, 43 - unsigned char *dst, 44 - int len, unsigned int sum); 43 + extern __wsum csum_partial_copy_nocheck(const void *src, void *dst, 44 + int len, __wsum sum); 45 45 46 46 /* 47 47 * This is a new version of the above that records errors it finds in *errp, 48 48 * but continues and zeros thre rest of the buffer. 49 49 */ 50 - extern unsigned int csum_partial_copy_from_user(const unsigned char __user *src, 51 - unsigned char *dst, 52 - int len, unsigned int sum, 50 + extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst, 51 + int len, __wsum sum, 53 52 int *err_ptr); 54 53 55 54 /* 56 55 * Fold a partial checksum 57 56 */ 58 57 59 - static inline unsigned int csum_fold(unsigned int sum) 58 + static inline __sum16 csum_fold(__wsum sum) 60 59 { 61 60 unsigned long tmpreg; 62 61 __asm__( ··· 69 72 : "0" (sum) 70 73 : "cbit" 71 74 ); 72 - return sum; 75 + return (__force __sum16)sum; 73 76 } 74 77 75 78 /* 76 79 * This is a version of ip_compute_csum() optimized for IP headers, 77 80 * which always checksum on 4 octet boundaries. 78 81 */ 79 - static inline unsigned short ip_fast_csum(unsigned char * iph, 80 - unsigned int ihl) { 81 - unsigned long sum, tmpreg0, tmpreg1; 82 + static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 83 + { 84 + unsigned long tmpreg0, tmpreg1; 85 + __wsum sum; 82 86 83 87 __asm__ __volatile__( 84 88 " ld %0, @%1+ \n" ··· 113 115 return csum_fold(sum); 114 116 } 115 117 116 - static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, 117 - unsigned long daddr, 118 + static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 118 119 unsigned short len, 119 120 unsigned short proto, 120 - unsigned int sum) 121 + __wsum sum) 121 122 { 122 123 #if defined(__LITTLE_ENDIAN) 123 - unsigned long len_proto = (ntohs(len)<<16)+proto*256; 124 + unsigned long len_proto = (proto + len) << 8; 124 125 #else 125 - unsigned long len_proto = (proto<<16)+len; 126 + unsigned long len_proto = proto + len; 126 127 #endif 127 128 unsigned long tmpreg; 128 129 ··· 144 147 * computes the checksum of the TCP/UDP pseudo-header 145 148 * returns a 16-bit checksum, already complemented 146 149 */ 147 - static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 148 - unsigned long daddr, 150 + static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 149 151 unsigned short len, 150 152 unsigned short proto, 151 - unsigned int sum) 153 + __wsum sum) 152 154 { 153 155 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 154 156 } ··· 157 161 * in icmp.c 158 162 */ 159 163 160 - static inline unsigned short ip_compute_csum(unsigned char * buff, int len) { 164 + static inline __sum16 ip_compute_csum(const void *buff, int len) 165 + { 161 166 return csum_fold (csum_partial(buff, len, 0)); 162 167 } 163 168 164 169 #define _HAVE_ARCH_IPV6_CSUM 165 - static inline unsigned short int csum_ipv6_magic(struct in6_addr *saddr, 166 - struct in6_addr *daddr, 167 - __u16 len, 168 - unsigned short proto, 169 - unsigned int sum) 170 + static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, 171 + const struct in6_addr *daddr, 172 + __u32 len, unsigned short proto, 173 + __wsum sum) 170 174 { 171 175 unsigned long tmpreg0, tmpreg1, tmpreg2, tmpreg3; 172 176 __asm__( ··· 193 197 : "=&r" (sum), "=&r" (tmpreg0), "=&r" (tmpreg1), 194 198 "=&r" (tmpreg2), "=&r" (tmpreg3) 195 199 : "r" (saddr), "r" (daddr), 196 - "r" (htonl((__u32) (len))), "r" (htonl(proto)), "0" (sum) 200 + "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) 197 201 : "cbit" 198 202 ); 199 203