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

[NET]: UML checksum annotations and cleanups.

* sanitize prototypes, annotate
* kill csum_partial_copy_fromuser
* kill shift-by-16 in checksum calculations
* ntohs->shift 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
abf419b8 c459dd90

+53 -68
+30 -44
arch/um/include/sysdep-i386/checksum.h
··· 20 20 * 21 21 * it's best to have buff aligned on a 32-bit boundary 22 22 */ 23 - unsigned int csum_partial(const unsigned char * buff, int len, 24 - unsigned int sum); 23 + __wsum csum_partial(const void *buff, int len, __wsum sum); 25 24 26 25 /* 27 26 * Note: when you get a NULL pointer exception here this means someone ··· 31 32 */ 32 33 33 34 static __inline__ 34 - unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, 35 - int len, int sum) 35 + __wsum csum_partial_copy_nocheck(const void *src, void *dst, 36 + int len, __wsum sum) 36 37 { 37 38 memcpy(dst, src, len); 38 39 return csum_partial(dst, len, sum); ··· 47 48 */ 48 49 49 50 static __inline__ 50 - unsigned int csum_partial_copy_from_user(const unsigned char __user *src, 51 - unsigned char *dst, 52 - int len, int sum, int *err_ptr) 51 + __wsum csum_partial_copy_from_user(const void __user *src, void *dst, 52 + int len, __wsum sum, int *err_ptr) 53 53 { 54 - if(copy_from_user(dst, src, len)){ 54 + if (copy_from_user(dst, src, len)) { 55 55 *err_ptr = -EFAULT; 56 - return(-1); 56 + return (__force __wsum)-1; 57 57 } 58 58 59 59 return csum_partial(dst, len, sum); 60 60 } 61 - 62 - /* 63 - * These are the old (and unsafe) way of doing checksums, a warning message 64 - * will be printed if they are used and an exception occurs. 65 - * 66 - * these functions should go away after some time. 67 - */ 68 - 69 - #define csum_partial_copy_fromuser csum_partial_copy_from_user 70 61 71 62 /* 72 63 * This is a version of ip_compute_csum() optimized for IP headers, ··· 65 76 * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by 66 77 * Arnt Gulbrandsen. 67 78 */ 68 - static inline unsigned short ip_fast_csum(unsigned char * iph, 69 - unsigned int ihl) 79 + static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 70 80 { 71 81 unsigned int sum; 72 82 ··· 93 105 : "=r" (sum), "=r" (iph), "=r" (ihl) 94 106 : "1" (iph), "2" (ihl) 95 107 : "memory"); 96 - return sum; 108 + return (__force __sum16)sum; 97 109 } 98 110 99 111 /* 100 112 * Fold a partial checksum 101 113 */ 102 114 103 - static inline unsigned int csum_fold(unsigned int sum) 115 + static inline __sum16 csum_fold(__wsum sum) 104 116 { 105 117 __asm__( 106 118 "addl %1, %0 ;\n" 107 119 "adcl $0xffff, %0 ;\n" 108 120 : "=r" (sum) 109 - : "r" (sum << 16), "0" (sum & 0xffff0000) 121 + : "r" ((__force u32)sum << 16), 122 + "0" ((__force u32)sum & 0xffff0000) 110 123 ); 111 - return (~sum) >> 16; 124 + return (__force __sum16)(~(__force u32)sum >> 16); 112 125 } 113 126 114 - static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, 115 - unsigned long daddr, 127 + static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 116 128 unsigned short len, 117 129 unsigned short proto, 118 - unsigned int sum) 130 + __wsum sum) 119 131 { 120 132 __asm__( 121 133 "addl %1, %0 ;\n" ··· 123 135 "adcl %3, %0 ;\n" 124 136 "adcl $0, %0 ;\n" 125 137 : "=r" (sum) 126 - : "g" (daddr), "g"(saddr), "g"((ntohs(len)<<16)+proto*256), "0"(sum)); 138 + : "g" (daddr), "g"(saddr), "g"((len + proto) << 8), "0"(sum)); 127 139 return sum; 128 140 } 129 141 ··· 131 143 * computes the checksum of the TCP/UDP pseudo-header 132 144 * returns a 16-bit checksum, already complemented 133 145 */ 134 - static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 135 - unsigned long daddr, 146 + static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 136 147 unsigned short len, 137 148 unsigned short proto, 138 - unsigned int sum) 149 + __wsum sum) 139 150 { 140 151 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 141 152 } ··· 144 157 * in icmp.c 145 158 */ 146 159 147 - static inline unsigned short ip_compute_csum(unsigned char * buff, int len) 160 + static inline __sum16 ip_compute_csum(const void *buff, int len) 148 161 { 149 162 return csum_fold (csum_partial(buff, len, 0)); 150 163 } 151 164 152 165 #define _HAVE_ARCH_IPV6_CSUM 153 - static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, 154 - struct in6_addr *daddr, 155 - __u32 len, 156 - unsigned short proto, 157 - unsigned int sum) 166 + static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, 167 + const struct in6_addr *daddr, 168 + __u32 len, unsigned short proto, 169 + __wsum sum) 158 170 { 159 171 __asm__( 160 172 "addl 0(%1), %0 ;\n" ··· 178 192 * Copy and checksum to user 179 193 */ 180 194 #define HAVE_CSUM_COPY_USER 181 - static __inline__ unsigned int csum_and_copy_to_user(const unsigned char *src, 182 - unsigned char __user *dst, 183 - int len, int sum, int *err_ptr) 195 + static __inline__ __wsum csum_and_copy_to_user(const void *src, 196 + void __user *dst, 197 + int len, __wsum sum, int *err_ptr) 184 198 { 185 - if (access_ok(VERIFY_WRITE, dst, len)){ 186 - if(copy_to_user(dst, src, len)){ 199 + if (access_ok(VERIFY_WRITE, dst, len)) { 200 + if (copy_to_user(dst, src, len)) { 187 201 *err_ptr = -EFAULT; 188 - return(-1); 202 + return (__force __wsum)-1; 189 203 } 190 204 191 205 return csum_partial(src, len, sum); ··· 194 208 if (len) 195 209 *err_ptr = -EFAULT; 196 210 197 - return -1; /* invalid checksum */ 211 + return (__force __wsum)-1; /* invalid checksum */ 198 212 } 199 213 200 214 #endif
+23 -24
arch/um/include/sysdep-x86_64/checksum.h
··· 9 9 #include "linux/in6.h" 10 10 #include "asm/uaccess.h" 11 11 12 - extern unsigned csum_partial(const unsigned char *buff, unsigned len, 13 - unsigned sum); 12 + extern __wsum csum_partial(const void *buff, int len, __wsum sum); 14 13 15 14 /* 16 15 * Note: when you get a NULL pointer exception here this means someone ··· 20 21 */ 21 22 22 23 static __inline__ 23 - unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, 24 - int len, int sum) 24 + __wsum csum_partial_copy_nocheck(const void *src, void *dst, 25 + int len, __wsum sum) 25 26 { 26 27 memcpy(dst, src, len); 27 28 return(csum_partial(dst, len, sum)); 28 29 } 29 30 30 31 static __inline__ 31 - unsigned int csum_partial_copy_from_user(const unsigned char *src, 32 - unsigned char *dst, int len, int sum, 32 + __wsum csum_partial_copy_from_user(const void __user *src, 33 + void *dst, int len, __wsum sum, 33 34 int *err_ptr) 34 35 { 35 - if(copy_from_user(dst, src, len)){ 36 + if (copy_from_user(dst, src, len)) { 36 37 *err_ptr = -EFAULT; 37 - return(-1); 38 + return (__force __wsum)-1; 38 39 } 39 40 return csum_partial(dst, len, sum); 40 41 } ··· 47 48 * the last step before putting a checksum into a packet. 48 49 * Make sure not to mix with 64bit checksums. 49 50 */ 50 - static inline unsigned int csum_fold(unsigned int sum) 51 + static inline __sum16 csum_fold(__wsum sum) 51 52 { 52 53 __asm__( 53 54 " addl %1,%0\n" 54 55 " adcl $0xffff,%0" 55 56 : "=r" (sum) 56 - : "r" (sum << 16), "0" (sum & 0xffff0000) 57 + : "r" ((__force u32)sum << 16), 58 + "0" ((__force u32)sum & 0xffff0000) 57 59 ); 58 - return (~sum) >> 16; 60 + return (__force __sum16)(~(__force u32)sum >> 16); 59 61 } 60 62 61 63 /** ··· 70 70 * Returns the pseudo header checksum the input data. Result is 71 71 * 32bit unfolded. 72 72 */ 73 - static inline unsigned long 74 - csum_tcpudp_nofold(unsigned saddr, unsigned daddr, unsigned short len, 75 - unsigned short proto, unsigned int sum) 73 + static inline __wsum 74 + csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len, 75 + unsigned short proto, __wsum sum) 76 76 { 77 77 asm(" addl %1, %0\n" 78 78 " adcl %2, %0\n" 79 79 " adcl %3, %0\n" 80 80 " adcl $0, %0\n" 81 81 : "=r" (sum) 82 - : "g" (daddr), "g" (saddr), "g" ((ntohs(len)<<16)+proto*256), "0" (sum)); 83 - return sum; 82 + : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum)); 83 + return sum; 84 84 } 85 85 86 86 /* 87 87 * computes the checksum of the TCP/UDP pseudo-header 88 88 * returns a 16-bit checksum, already complemented 89 89 */ 90 - static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 91 - unsigned long daddr, 92 - unsigned short len, 93 - unsigned short proto, 94 - unsigned int sum) 90 + static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 91 + unsigned short len, 92 + unsigned short proto, 93 + __wsum sum) 95 94 { 96 95 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 97 96 } ··· 100 101 * iph: ipv4 header 101 102 * ihl: length of header / 4 102 103 */ 103 - static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) 104 + static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 104 105 { 105 106 unsigned int sum; 106 107 ··· 127 128 : "=r" (sum), "=r" (iph), "=r" (ihl) 128 129 : "1" (iph), "2" (ihl) 129 130 : "memory"); 130 - return(sum); 131 + return (__force __sum16)sum; 131 132 } 132 133 133 134 static inline unsigned add32_with_carry(unsigned a, unsigned b) ··· 139 140 return a; 140 141 } 141 142 142 - extern unsigned short ip_compute_csum(unsigned char * buff, int len); 143 + extern __sum16 ip_compute_csum(const void *buff, int len); 143 144 144 145 #endif