diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2006-11-15 00:19:22 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:23:12 -0500 |
commit | abf419b809bed2333267e4b23dd2b3b4f10da88c (patch) | |
tree | 69f47b8df85bac6cc2d158035932c9eee5a30625 /arch/um/include/sysdep-x86_64 | |
parent | c459dd90f0de00db1ca1328482214019f6ca292f (diff) |
[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>
Diffstat (limited to 'arch/um/include/sysdep-x86_64')
-rw-r--r-- | arch/um/include/sysdep-x86_64/checksum.h | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/arch/um/include/sysdep-x86_64/checksum.h b/arch/um/include/sysdep-x86_64/checksum.h index ea97005af694..a5be9031ea85 100644 --- a/arch/um/include/sysdep-x86_64/checksum.h +++ b/arch/um/include/sysdep-x86_64/checksum.h | |||
@@ -9,8 +9,7 @@ | |||
9 | #include "linux/in6.h" | 9 | #include "linux/in6.h" |
10 | #include "asm/uaccess.h" | 10 | #include "asm/uaccess.h" |
11 | 11 | ||
12 | extern unsigned csum_partial(const unsigned char *buff, unsigned len, | 12 | extern __wsum csum_partial(const void *buff, int len, __wsum sum); |
13 | unsigned sum); | ||
14 | 13 | ||
15 | /* | 14 | /* |
16 | * Note: when you get a NULL pointer exception here this means someone | 15 | * Note: when you get a NULL pointer exception here this means someone |
@@ -21,21 +20,21 @@ extern unsigned csum_partial(const unsigned char *buff, unsigned len, | |||
21 | */ | 20 | */ |
22 | 21 | ||
23 | static __inline__ | 22 | static __inline__ |
24 | unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, | 23 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, |
25 | int len, int sum) | 24 | int len, __wsum sum) |
26 | { | 25 | { |
27 | memcpy(dst, src, len); | 26 | memcpy(dst, src, len); |
28 | return(csum_partial(dst, len, sum)); | 27 | return(csum_partial(dst, len, sum)); |
29 | } | 28 | } |
30 | 29 | ||
31 | static __inline__ | 30 | static __inline__ |
32 | unsigned int csum_partial_copy_from_user(const unsigned char *src, | 31 | __wsum csum_partial_copy_from_user(const void __user *src, |
33 | unsigned char *dst, int len, int sum, | 32 | void *dst, int len, __wsum sum, |
34 | int *err_ptr) | 33 | int *err_ptr) |
35 | { | 34 | { |
36 | if(copy_from_user(dst, src, len)){ | 35 | if (copy_from_user(dst, src, len)) { |
37 | *err_ptr = -EFAULT; | 36 | *err_ptr = -EFAULT; |
38 | return(-1); | 37 | return (__force __wsum)-1; |
39 | } | 38 | } |
40 | return csum_partial(dst, len, sum); | 39 | return csum_partial(dst, len, sum); |
41 | } | 40 | } |
@@ -48,15 +47,16 @@ unsigned int csum_partial_copy_from_user(const unsigned char *src, | |||
48 | * the last step before putting a checksum into a packet. | 47 | * the last step before putting a checksum into a packet. |
49 | * Make sure not to mix with 64bit checksums. | 48 | * Make sure not to mix with 64bit checksums. |
50 | */ | 49 | */ |
51 | static inline unsigned int csum_fold(unsigned int sum) | 50 | static inline __sum16 csum_fold(__wsum sum) |
52 | { | 51 | { |
53 | __asm__( | 52 | __asm__( |
54 | " addl %1,%0\n" | 53 | " addl %1,%0\n" |
55 | " adcl $0xffff,%0" | 54 | " adcl $0xffff,%0" |
56 | : "=r" (sum) | 55 | : "=r" (sum) |
57 | : "r" (sum << 16), "0" (sum & 0xffff0000) | 56 | : "r" ((__force u32)sum << 16), |
57 | "0" ((__force u32)sum & 0xffff0000) | ||
58 | ); | 58 | ); |
59 | return (~sum) >> 16; | 59 | return (__force __sum16)(~(__force u32)sum >> 16); |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | 62 | /** |
@@ -70,28 +70,27 @@ static inline unsigned int csum_fold(unsigned int sum) | |||
70 | * Returns the pseudo header checksum the input data. Result is | 70 | * Returns the pseudo header checksum the input data. Result is |
71 | * 32bit unfolded. | 71 | * 32bit unfolded. |
72 | */ | 72 | */ |
73 | static inline unsigned long | 73 | static inline __wsum |
74 | csum_tcpudp_nofold(unsigned saddr, unsigned daddr, unsigned short len, | 74 | csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len, |
75 | unsigned short proto, unsigned int sum) | 75 | unsigned short proto, __wsum sum) |
76 | { | 76 | { |
77 | asm(" addl %1, %0\n" | 77 | asm(" addl %1, %0\n" |
78 | " adcl %2, %0\n" | 78 | " adcl %2, %0\n" |
79 | " adcl %3, %0\n" | 79 | " adcl %3, %0\n" |
80 | " adcl $0, %0\n" | 80 | " adcl $0, %0\n" |
81 | : "=r" (sum) | 81 | : "=r" (sum) |
82 | : "g" (daddr), "g" (saddr), "g" ((ntohs(len)<<16)+proto*256), "0" (sum)); | 82 | : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum)); |
83 | return sum; | 83 | return sum; |
84 | } | 84 | } |
85 | 85 | ||
86 | /* | 86 | /* |
87 | * computes the checksum of the TCP/UDP pseudo-header | 87 | * computes the checksum of the TCP/UDP pseudo-header |
88 | * returns a 16-bit checksum, already complemented | 88 | * returns a 16-bit checksum, already complemented |
89 | */ | 89 | */ |
90 | static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | 90 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
91 | unsigned long daddr, | 91 | unsigned short len, |
92 | unsigned short len, | 92 | unsigned short proto, |
93 | unsigned short proto, | 93 | __wsum sum) |
94 | unsigned int sum) | ||
95 | { | 94 | { |
96 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); | 95 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); |
97 | } | 96 | } |
@@ -101,7 +100,7 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | |||
101 | * iph: ipv4 header | 100 | * iph: ipv4 header |
102 | * ihl: length of header / 4 | 101 | * ihl: length of header / 4 |
103 | */ | 102 | */ |
104 | static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) | 103 | static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
105 | { | 104 | { |
106 | unsigned int sum; | 105 | unsigned int sum; |
107 | 106 | ||
@@ -128,7 +127,7 @@ static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) | |||
128 | : "=r" (sum), "=r" (iph), "=r" (ihl) | 127 | : "=r" (sum), "=r" (iph), "=r" (ihl) |
129 | : "1" (iph), "2" (ihl) | 128 | : "1" (iph), "2" (ihl) |
130 | : "memory"); | 129 | : "memory"); |
131 | return(sum); | 130 | return (__force __sum16)sum; |
132 | } | 131 | } |
133 | 132 | ||
134 | static inline unsigned add32_with_carry(unsigned a, unsigned b) | 133 | static inline unsigned add32_with_carry(unsigned a, unsigned b) |
@@ -140,6 +139,6 @@ static inline unsigned add32_with_carry(unsigned a, unsigned b) | |||
140 | return a; | 139 | return a; |
141 | } | 140 | } |
142 | 141 | ||
143 | extern unsigned short ip_compute_csum(unsigned char * buff, int len); | 142 | extern __sum16 ip_compute_csum(const void *buff, int len); |
144 | 143 | ||
145 | #endif | 144 | #endif |